Created
May 16, 2018 03:54
-
-
Save gtkatakura/1178922a64b0d624f9138481bdc840b2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 flatten = array => [].concat(...array) | |
const uniq = array => array.reduce((filtered, element) => ( | |
filtered.includes(element) | |
? filtered | |
: [...filtered, element] | |
), []) | |
const normalize = array => uniq(flatten(array)).sort() | |
} | |
Grammar | |
= symbols:Expression+ { return normalize(symbols) } | |
Expression | |
= left:TermExpression rights:("|" TermExpression)* { return left.concat(rights ? flatten(rights.map(right => right[1])) : []) } | |
TermExpression | |
= symbols:(Alphanumeric+ / CaptureExpression) RepetitionPart? { return symbols } | |
CaptureExpression | |
= "(" symbols:Expression+ ")" { return flatten(symbols) } | |
AlphanumericExpression | |
= symbols:Alphanumeric+ { return symbols } | |
RepetitionPart | |
= ("?" / "+" / "*" / "{" Integer+ "}")? | |
Alphanumeric | |
= (Integer / Letter) | |
Integer "integer" | |
= [0-9] | |
Letter "letter" | |
= [a-z] | |
_ "whitespace" | |
= [ \t\n\r]* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment