finn-lang/grammar.txt

38 lines
1.2 KiB
Plaintext

expression ->
| sequence
// | apply
| unary
| binary
// | let
| compound
| control
| field
| index
| identifier
| primary
grouping -> "(" expression ")" ;
unary -> ( "-" | "!" ) expression ;
binary -> expression operator expression ;
operator ->
| "==" | "!=" | "<" | "<=" | ">" | ">="
| "+" | "-" | "*" | "/"
// | "|>" | "<|" | ">>" | "<<"
| "++" ;
control ->
| if
| when
if -> "if" expression "then" expression "else" expression ;
variant_pattern -> "`" identifier ( "(" ( ( "_" | identifier ) ( "," ( "_" | identifier )* )? ) ")" )? ;
when -> "when" expression "is" ( variant_pattern "=>" expression )+ ;
compound -> variant | record | list ;
variant -> "`" identifier ( "(" ( expression ( "," expression)* )? ")" )? ;
base_record -> expression ( "with" identifier "=" expression ( "," "with" identifier "=" expression )* )?
record ->
"{" ( identifier ("=" expression)? ( "," identifier ("=" expression)? )* )? ( "|" base_record )* "}" ;
list -> "[" ( expression ( "," expression )* )? "]" ;
field -> expression "." identifier ;
index -> expression "[" expression "]" ;
identifier -> IDENTIFIER | "@" STRING ;
primary -> NUMBER | STRING | identifier | "(" expression ")" ;