Created
August 19, 2019 14:25
-
-
Save LeonAlvarez/1f25e71ec4db10c4b5e09b53627b3aa7 to your computer and use it in GitHub Desktop.
consume string rule
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