agtest/grammar.lark

53 lines
1 KiB
Text
Raw Normal View History

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