agtest/grammar.lark
2021-06-09 02:44:52 -05:00

53 lines
No EOL
1 KiB
Text

program: decl*
?decl: iface
| node
| func
sep_trail{item, punc}: item (punc item)? punc?
func: "fn" ident "(" ")" ("->" ty) "{" "}"
iface: "iface" ident "{" sep_trail{iface_field, ","} "}"
iface_field: ident ":" ident
iface_ref: ident
iface_refs: iface_ref*
node: "node" ident ":" iface_refs "{" variants "}"
variants: variant*
variant: prod "=>" "{" equations "}"
prod: sym*
sym: sym_rename
| STRING
sym_rename: "<" ident ":" node_ref ">"
node_ref: node_ref_name
| STRING
node_ref_name: ident
equations: equation_*
equation_: equation ";"
// TODO: the left side should really be a separate type
// called lvalue, and should NOT include literals
equation: expr "=" expr
expr: expr_dot
| expr_add
| expr_mul
| expr_call
| expr_name
expr_dot: expr "." expr
expr_add: expr "+" expr
expr_mul: expr "*" expr
expr_call: expr "(" args ")"
expr_name: ident
args: sep_trail{expr, ","}
ty: ident
ident: IDENT
COMMENT: /\/\/[^\n]*/
IDENT: /([a-zA-Z][a-zA-Z0-9_]*)|(_[a-zA-Z0-9_]+)/
%import python.STRING
%import common.WS
%ignore WS
%ignore COMMENT