44 lines
1.3 KiB
EBNF
44 lines
1.3 KiB
EBNF
// W3C EBNF syntax definition for Midas
|
|
Identifier ::= [a-zA-Z_] [a-zA-Z_0-9]*
|
|
|
|
Integer ::= '\d+'
|
|
Number ::= "-"? Integer ("." Integer)?
|
|
Boolean ::= "False" | "True"
|
|
None ::= "None"
|
|
|
|
Value ::= Number | Boolean | None
|
|
|
|
ComparisonOp ::= ">" | "<" | ">=" | "<="
|
|
EqualityOp ::= "==" | "!="
|
|
|
|
Grouping ::= "(" Constraint ")"
|
|
Primary ::= "_" | Value | Identifier | Grouping
|
|
Reference ::= Primary ("." Identifier)*
|
|
Unary ::= "-"? Unary | Reference
|
|
Comparison ::= Unary (ComparisonOp Unary)*
|
|
Equality ::= Comparison (EqualityOp Comparison)*
|
|
Constraint ::= Equality ("&" Equality)*
|
|
|
|
TemplateParam ::= Identifier ("<:" Type)?
|
|
Template ::= "[" (TemplateParam ("," TemplateParam)*)? "]"
|
|
|
|
|
|
TypeProperty ::= Identifier ":" Type
|
|
ComplexType ::= "{" TypeProperty* "}"
|
|
NamedType ::= Identifier
|
|
TypeParams ::= "[" (Type ("," Type)*)? "]"
|
|
GenericType ::= NamedType TypeParams?
|
|
GroupedType ::= "(" Type ")"
|
|
BaseType ::= GroupedType | ComplexType | GenericType
|
|
ConstraintType ::= BaseType ("where" Constraint)?
|
|
Type ::= ConstraintType
|
|
|
|
OpDefinition ::= "op" Identifier "(" Type ")" "->" Type
|
|
ExtendBody ::= "{" OpDefinition* "}"
|
|
|
|
TypeStatement ::= "type" Identifier Template? "=" Type
|
|
ExtendStatement ::= "extend" Type ExtendBody
|
|
PredicateStatement ::= "predicate" Identifier "(" Identifier ":" Type ")" "=" Constraint
|
|
|
|
Statement ::= TypeStatement | ExtendStatement | PredicateStatement
|