Skip to content

Instantly share code, notes, and snippets.

@aziis98
Last active July 15, 2018 00:20
Show Gist options
  • Select an option

  • Save aziis98/cb917159e95a098a637e5e0faae7c05e to your computer and use it in GitHub Desktop.

Select an option

Save aziis98/cb917159e95a098a637e5e0faae7c05e to your computer and use it in GitHub Desktop.
// 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