Amo/grammar.ebnf
2022-04-06 09:23:46 -04:00

67 lines
2.5 KiB
EBNF

<program> ::= { DeclarationStart <declaration> }
<declaration> ::= Type Symbol { <typearg> } Assign <variant_decl> { VBar <variant_decl> }
| Struct Symbol { <typearg> } Assign { <def_field> }
| Trait Symbol { <typearg> } [ On <composite_type> ] Needs { <def_field> }
| Impl Symbol [ <typearg> ] On <composite_type> Colon <impl> { <impl> }
| Symbol <def>
<variant_declaration> ::= Symbol { <grouped_type> }
<full_type> ::= <composite_type> [ { Comma <composite_type> } Aro <full_type> ]
<composite_type> ::= <simple_type> { <grouped_type> }
<grouped_type> ::= <simple_type>
| OpenParen <full_type> CloseParen
<simple_type> ::= Symbol [ OpenSquareBracket <expr> CloseSquareBracket ]
<def_field> ::= Dot Symbol Colon <full_type>
<typearg> ::= Symbol [OpenSquareBracket <full_type> { Comma <full_type> } CloseSquareBracket]
<impl> ::= Dot Symbol { Symbol } Assign <expr>
<def> ::= Colon <full_type>
| { Symbol } Assign <expr>
<expr> ::= If <expr> <ifblock>
| <let> { <let> } In <expr>
| <infix_expr>
<tightexpr> ::= Literal
| { <multisymbol> }
| OpenParen <expr> CloseParen
<multisymbol> ::= Symbol { Dot Symbol }
<let> ::= Let Symbol Assign <expr>
<ifblock> ::= Is <case> { Comma <case> } [ Comma ]
| Then <expr> Else <expr>
<case> ::= <binding_pattern> Aro <expr>
<infix_rank1_expr> ::= <infix_rank2_expr> [ <infix_rank1_op> <infix_rank1_expr> ]
<infix_rank2_expr> ::= <infix_rank3_expr> [ <infix_rank2_op> <infix_rank2_expr> ]
<infix_rank3_expr> ::= <infix_rank4_expr> [ <infix_rank3_op> <infix_rank3_expr> ]
<infix_rank4_expr> ::= <infix_rank5_expr> [ <infix_rank4_op> <infix_rank4_expr> ]
<infix_rank5_expr> ::= <call_or_access> [ <infix_rank5_op> <infix_rank5_expr> ]
<infix_rank1_op> ::= Mult | Div | Mod
<infix_rank2_op> ::= Add | Sub
<infix_rank3_op> ::= Range
<infix_rank4_op> ::= Eq | NEq | LessThan | GreaterThan
<infix_rank5_op> ::= LAnd
<infix_rank6_op> ::= LOr
<call_or_access> ::= <tightexpr> { <tightexpr> }
<binding_pattern> ::= Symbol <bp_innards>
| Literal
<bp_innards> ::= <bp_field> { <bp_field> }
| { <binding_pattern> }
<bp_field> ::= Dot Symbol Assign <binding_pattern>