agtest/grammar.lark

65 lines
1.2 KiB
Text
Raw Normal View History

program: decl*
2021-06-09 00:56:30 +00:00
?decl: iface
2021-06-13 23:28:28 +00:00
| node
| 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-13 23:28:28 +00:00
?sym: sym_rename
2021-09-30 20:32:32 +00:00
| sym_lit
sym_lit: ESCAPED_STRING
sym_rename: "<" ident ":" node_ref ">"
2021-06-13 23:28:28 +00:00
?node_ref: node_ref_name
2021-09-30 20:32:32 +00:00
| node_regex
node_ref_name: ident
2021-09-30 20:32:32 +00:00
node_regex: ESCAPED_STRING
2021-06-13 23:28:28 +00:00
equations: equation_semi*
equation_semi: 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-13 23:28:28 +00:00
// Expressions
?expr: expr2
| expr_add
expr_add: expr "+" expr2
?expr2: expr3
| expr_mul
| expr_call
expr_mul: expr2 "*" expr3
expr_call: expr2 "(" args ")"
?expr3: "(" expr ")"
| expr_dot
| expr_name
expr_dot: expr3 "." ident
expr_name: ident
2021-06-13 23:28:28 +00:00
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-09-30 20:32:32 +00:00
%import common.ESCAPED_STRING
2021-06-09 07:44:52 +00:00
%ignore WS
2021-09-30 20:32:32 +00:00
%ignore COMMENT