agtest/grammar.lark

49 lines
819 B
Text
Raw Normal View History

2021-06-09 00:56:30 +00:00
start: decl*
decl: iface
| node
iface: IFACE IDENT "{" iface_field (COMMA iface_field)? COMMA? "}"
iface_field: IDENT COLON IDENT
2021-06-09 05:10:45 +00:00
node: NODE IDENT COLON IDENT "{" variant* "}"
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
2021-06-09 05:10:45 +00:00
sym_rename: "<" IDENT ":" node_ref ">"
2021-06-09 00:56:30 +00:00
node_ref: IDENT
| STRING
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
2021-06-09 00:56:30 +00:00
| IDENT
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
2021-06-09 00:56:30 +00:00
args: expr (COMMA expr)? COMMA?
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