Last active
July 15, 2018 00:20
-
-
Save aziis98/cb917159e95a098a637e5e0faae7c05e 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
| // Haskell-Like Type Syntax | |
| // for Fragment Editor | |
| // ======================== | |
| // | |
| start | |
| = Type | |
| Type | |
| = NamedType / ArrayType / ObjectType | |
| ObjectType | |
| = "{ " first:Field tail:(", " Field)* " }" { | |
| return [first].concat(tail.map(it => it[1])) | |
| .reduce((v, acc) => Object.assign(v, acc), { _: 'object' }); | |
| } | |
| Field | |
| = key:FieldName " : " type:Type { | |
| return { [key]: type } | |
| } | |
| ArrayType | |
| = "[" type:Type "]" { | |
| return { _: 'array', type } | |
| } | |
| NamedType | |
| = [a-zA-Z]+ { | |
| return { _: 'type', type: text() } | |
| } | |
| FieldName | |
| = ([a-zA-Z][a-zA-Z0-9]*) { | |
| return text() | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment