finn-lang/grammar.txt

35 lines
875 B
Plaintext
Raw 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-06-28 23:18:31 +00:00
| compound
| control
2023-06-28 21:52:39 +00:00
| field
| index
2023-06-28 23:18:31 +00:00
// | identifier
| primary
2023-06-28 21:52:39 +00:00
identifier -> IDENTIFIER | "@" STRING ;
2023-06-28 21:52:39 +00:00
grouping -> "(" expression ")" ;
unary -> ( "-" | "!" ) expression ;
binary -> expression operator expression ;
operator ->
| "==" | "!=" | "<" | "<=" | ">" | ">="
| "+" | "-" | "*" | "/"
// | "|>" | "<|" | ">>" | "<<"
2023-06-28 21:52:39 +00:00
| "++" ;
2023-06-28 23:18:31 +00:00
control ->
| if
// | when
2023-06-28 21:52:39 +00:00
if -> "if" expression "then" expression "else" expression ;
2023-06-28 23:18:31 +00:00
compound -> variant | record | list ;
variant -> "`" identifier ( "(" ( expression ( "," expression)* )? ")" )? ;
2023-06-28 21:52:39 +00:00
record ->
"{" ( identifier "=" expression ( "," identifier "=" expression )* )? "}" ;
2023-06-28 21:52:39 +00:00
list -> "[" ( expression ( "," expression )* )? "]" ;
field -> expression "." identifier ;
index -> expression "[" expression "]" ;
2023-06-28 23:18:31 +00:00
primary -> NUMBER | STRING | "(" expression ")" ;