Created
August 19, 2019 14:53
-
-
Save LeonAlvarez/8f7b024452a30727e850724a39126c08 to your computer and use it in GitHub Desktop.
consume string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const consumeAListOfRules = (str, topLevel) => { | |
let rules = []; | |
while (str.consume()) { | |
try { | |
const rule = consumeStringRule(str, topLevel); | |
if (rule) { | |
reules.push(rule) | |
} | |
} catch (error) { | |
return rules; | |
} | |
} | |
} | |
const consumeStringRule = (str, topLevel) => { | |
switch (true) { | |
case str.token instanceof WhitespaceToken: | |
return; | |
case (str.token instanceof CDOToken || str.token instanceof CDCToken) && topLevel === 'top-level': | |
return; | |
case str.token instanceof EOFToken: | |
throw new Error('EOF found'); | |
case str.token instanceof AtKeywordToken: | |
str.reconsume() | |
return consumeAnAtRule(str); | |
default: | |
str.reconsume() | |
return consumeAQualifiedRule(str); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment