forked from cizra/pycat
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmoo.lark
More file actions
89 lines (75 loc) · 2.45 KB
/
moo.lark
File metadata and controls
89 lines (75 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
?value: map
| list
| ESCAPED_STRING
| SIGNED_INT
| SIGNED_FLOAT
| OBJ_NUM
?expression: value
| assignment
| verb_call
| function_call
| subscript
| ternary
| compact_try
| prop_ref
| binary_expression
| logical_expression
| comparison
| "(" expression ")"
| spread
| unary_expression
| VAR
list : "{" [expression ("," expression)*] "}"
map : "[" [map_item ("," map_item)*] "]"
map_item : expression "->" expression
OBJ_NUM: "#" SIGNED_INT
prop_ref: expression "." expression
IN: "in"
VAR.-5: (("_"|"$"|LETTER) ("_"|LETTER|DIGIT)*)
arg_list : "(" [expression ("," expression)*] ")"
function_call: VAR arg_list
verb_call: expression ":" (VAR | ESCAPED_STRING | "(" expression ")") arg_list
?flow_statement: break | continue | return
break: "break" [VAR]
continue: "continue" [VAR]
return: "return" [expression]
?statement: (scatter_assignment | expression | flow_statement )? ";"
!binary_op: ("+" | "-" | "*" | "/" | "^" | "%" )
!comp_op: (IN | "==" | ">=" | "<=" | "!=" | "<" | ">" )
!logical_op: ("&&" | "||")
!unary_op: ("!" | "~" | "-")
assignment: (VAR | prop_ref | subscript) "=" expression
default_val: "?" VAR "=" expression
scatter_names: "{" [(VAR | default_val) ("," (VAR | default_val))*] "}"
scatter_assignment: scatter_names "=" expression
binary_expression: (expression binary_op expression)
unary_expression: unary_op expression
subscript: expression "[" ( slice | expression ) "]"
!slice_op: ".."
slice: (expression slice_op expression)
SPREAD_OP: "@"
spread: SPREAD_OP expression
comparison: expression (comp_op expression)+
logical_expression: expression (logical_op expression)+
if: "if" "(" expression ")" block elseif* else? "endif"
elseif: "elseif" "(" expression ")" block
else: "else" block
for: "for" expression ["," VAR] "in" ("[" expression "]" | "(" expression ")") block "endfor"
while: "while" VAR? "(" expression ")" block "endwhile"
fork: "fork" "(" expression ")" block "endfork"
ANY: "any"
try: "try" [block] except_block* [finally_block] "endtry"
except_block: except_clause block
except_clause: "except" [VAR] "(" (VAR | ANY ) ")"
finally_block: "finally" block
compact_try: "`" expression "!" (ANY | expression) ["=>" expression] "'"
ternary: (expression "?" expression "|" expression)
block: (statement | if | for | while | try | fork )*
start: block | value
%import common.ESCAPED_STRING
%import common.SIGNED_INT
%import common.SIGNED_FLOAT
%import common.WS
%import common.LETTER
%import common.DIGIT
%ignore WS