91 lines
2.5 KiB
EBNF
91 lines
2.5 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"
|
|
String ::= '(".*?")|(\'.*?\')'
|
|
None ::= "None"
|
|
|
|
Literal ::= Number | Boolean | String | None
|
|
|
|
UnaryOp ::= "+" | "-" | "!"
|
|
FactorOp ::= "*" | "/"
|
|
TermOp ::= "+" | "-"
|
|
ComparisonOp ::= ">" | "<" | ">=" | "<="
|
|
EqualityOp ::= "==" | "!="
|
|
|
|
PosArg ::= Expression
|
|
KwArg ::= Identifier "=" Expression
|
|
|
|
PosArgs ::= PosArg ("," PosArg)*
|
|
KwArgs ::= KwArg ("," KwArg)*
|
|
Args ::= (
|
|
PosArgs
|
|
| KwArgs
|
|
| PosArgs "," KwArgs
|
|
)
|
|
|
|
Grouping ::= "(" Expression ")"
|
|
Primary ::= "_" | Literal | Identifier | Grouping
|
|
Reference ::= Primary ("." Identifier)*
|
|
CallArgs ::= "(" Args ")"
|
|
Call ::= Reference CallArgs*
|
|
Unary ::= UnaryOp Unary | Call
|
|
Factor ::= Unary (FactorOp Unary)*
|
|
Term ::= Factor (TermOp Factor)*
|
|
Comparison ::= Term (ComparisonOp Term)*
|
|
Equality ::= Comparison (EqualityOp Comparison)*
|
|
Expression ::= Equality ("&" Equality)*
|
|
Constraint ::= Expression
|
|
|
|
TemplateParam ::= Identifier ("<:" Type)?
|
|
Template ::= "[" (TemplateParam ("," TemplateParam)*)? "]"
|
|
|
|
ParamType ::= Type "?"?
|
|
PosParam ::= (Identifier ":")? ParamType
|
|
KwParam ::= Identifier ":" ParamType
|
|
|
|
PosParams ::= (
|
|
(PosParam ("," PosParam)* ("," "/")?)
|
|
| "/"
|
|
)
|
|
MixedParams ::= KwParam ("," KwParam)
|
|
KwParams ::= (
|
|
(("*", ",")? KwParam ("," KwParam)*)
|
|
| "*"
|
|
)
|
|
Params ::= (
|
|
PosParams
|
|
| MixedParams
|
|
| KwParams
|
|
| (PosParams "," MixedParams)
|
|
| (PosParams "," KwParams)
|
|
| (MixedParams "," KwParams)
|
|
| (PosParams "," MixedParams "," KwParams)
|
|
)
|
|
ParamSpec ::= "(" Params? ")"
|
|
|
|
TypeProperty ::= Identifier ":" Type
|
|
ComplexType ::= "{" TypeProperty* "}"
|
|
NamedType ::= Identifier
|
|
TypeArgs ::= "[" (Type ("," Type)*)? "]"
|
|
FrameColumn ::= TOKEN ":" Type
|
|
FrameSchema ::= "[" (FrameColumn ("," FrameColumn)*)? "]"
|
|
GenericType ::= "Frame" FrameSchema | NamedType TypeArgs?
|
|
GroupedType ::= "(" Type ")"
|
|
BaseType ::= GroupedType | ComplexType | GenericType
|
|
ConstraintType ::= BaseType ("where" Constraint)?
|
|
FuncType ::= "fn" ParamSpec "->" Type
|
|
Type ::= ConstraintType
|
|
|
|
MemberStatement ::= ("prop" | "def") Identifier ":" Type
|
|
ExtendBody ::= "{" MemberStatement* "}"
|
|
|
|
AliasStatement ::= "alias" Identifier "=" Type
|
|
TypeStatement ::= "type" Identifier Template? "=" Type
|
|
ExtendStatement ::= "extend" Type ExtendBody
|
|
PredicateStatement ::= "predicate" Identifier ParamSpec* "=" Constraint
|
|
|
|
Statement ::= AliasStatement | TypeStatement | ExtendStatement | PredicateStatement
|