agtest/grammar.lark

54 lines
919 B
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
sep_trail{item, punc}: item (punc item)? punc?
2021-06-09 00:56:30 +00:00
iface: "iface" ident "{" sep_trail{iface_field, ","} "}"
iface_field: ident ":" ident
node: NODE ident ":" ident "{" variant* "}"
2021-06-09 05:10:45 +00:00
variant: prod "=>" "{" equation_* "}"
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 05:10:45 +00:00
equation_: equation SEMI
2021-06-09 00:56:30 +00:00
equation: expr EQ expr
2021-06-09 05:10:45 +00:00
expr: expr_dot
| expr_add
| expr_mul
| expr_call
| expr_name
2021-06-09 05:10:45 +00:00
expr_dot: expr DOT expr
expr_add: expr ADD expr
expr_mul: expr MUL expr
expr_call: expr LPAR args RPAR
expr_name: ident
2021-06-09 00:56:30 +00:00
args: expr (COMMA expr)? COMMA?
ident: IDENT
2021-06-09 00:56:30 +00:00
IDENT: /([a-zA-Z][a-zA-Z0-9_]*)|(_[a-zA-Z0-9_]+)/
IFACE: "iface"
NODE: "node"
LANG: "<"
RANG: ">"
ADD: "+"
MUL: "*"
COMMA: ","
COLON: ":"
LPAR: "("
RPAR: ")"
EQ: "="
DOT: "."
SEMI: ";"
THICCARROW: "=>"
%import python.STRING
%import common.WS
%ignore WS