Created
March 5, 2020 01:25
-
-
Save pfrazee/242a3b9142ab25781ca10b4d7e409096 to your computer and use it in GitHub Desktop.
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
// Webterm Input Grammar (PEG.js) | |
// ============================== | |
Expression | |
= Term+ | |
Term | |
= term:Switch _? { return {type: 'param', key: term.key, value: term.value} } | |
/ term:String _? { return {type: 'token', value: term} } | |
Switch "switch" | |
= '-'+ key:String _+ value:NonSwitch { return {key, value} } | |
/ '-'+ key:String { return {key, value: undefined} } | |
NonSwitch "non-switch" | |
= !'-' value:String { return value } | |
String "string" | |
= head:Char rest:CharOrQuote* { return head + rest.join('') } | |
/ '"' value:CharOr_OrSingleQuote* '"' { return value.join('') } | |
/ '\'' value:CharOr_OrDoubleQuote* '\'' { return value.join('') } | |
CharOr_OrDoubleQuote "character, whitespace, or double quote" | |
= CharOr_ | |
/ '"' | |
CharOr_OrSingleQuote "character, whitespace, or single quote" | |
= CharOr_ | |
/ '\'' | |
CharOr_ "character or whitespace" | |
= Char | |
/ _ | |
CharOrQuote "character, single quote, or double quote" | |
= Char | |
/ '\'' | |
/ '"' | |
Char "character" | |
= '\\ ' { return ' ' } // escaped space | |
/ [^ "'\f\n\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]i // regular characters | |
_ "whitespace" | |
= [ \t]+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment