finn-lang/grammar.txt

36 lines
1.5 KiB
Plaintext
Raw Permalink Normal View History

2023-06-28 21:52:39 +00:00
expression ->
2023-06-28 23:18:31 +00:00
| sequence
| apply
2023-06-28 21:52:39 +00:00
| unary
| binary
| let
2023-07-05 14:52:14 +00:00
| if
| when
2023-06-28 23:18:31 +00:00
| primary
2023-06-28 21:52:39 +00:00
grouping -> "(" expression ")" ;
unary -> ( "-" | "!" ) expression ;
binary -> expression operator expression ;
operator ->
| "==" | "!=" | "<" | "<=" | ">" | ">="
| "+" | "-" | "*" | "/"
| "++" ;
pattern -> "_" | record_pattern | variant_pattern ;
record_pattern -> "{" ( identifier ( "=" pattern )? ( "," identifier ( "=" pattern )? )* ) ( "|" identifier ) "}"
variant_pattern -> "`" identifier ( "(" ( "_" | compound_pattern | identifier ) ")" )? ;
parameters -> "(" ( identifier ( "," identifier )* )?")"
let -> "let" ( identifier parameters? | pattern ) "=" expression ( "and" ( identifier parameters? | pattern ) "=" expression )* "in" expression ;
2023-06-28 21:52:39 +00:00
if -> "if" expression "then" expression "else" expression ;
2023-07-05 14:52:14 +00:00
when -> "when" expression "is" ( identifier | pattern ) "=>" expression ( "," ( identifier | pattern ) "=>" expression )* ;
variant -> "`" identifier ( "(" expression ")" )? ;
base_record -> expression ( "with" identifier "=" expression ( "," identifier "=" expression )* ","? )?
2023-06-28 21:52:39 +00:00
record ->
"{" ( identifier ("=" expression)? ( "," identifier ("=" expression)? )* )? ( "|" base_record )? "}" ;
list -> "[" ( expression ( "," expression )* ","? )? "]" ;
2023-06-29 15:55:45 +00:00
identifier -> IDENTIFIER | "@" STRING ;
operand -> ( NUMBER | STRING | identifier | "(" expression ")" | record | variant | list) ;
selector -> "." identifier ;
index -> "[" expression "]" ;
call -> "(" ( ( "_" | expression ) ( "," ( "_" | expression ) )* ","? )? ")" ;
primary -> operand ( selector | index | call ) ;