forked from ggorlen/rene
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrene.lark
79 lines (62 loc) · 1.7 KB
/
rene.lark
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
?start: statement*
?statement: expr _NL
| blank_line
| comment
| for_block
| if_block
| func_def
| assignment
| array_assignment
| return_statement
| import
| from_import
func_def: "function" NAME "(" ((NAME ":" type ",")* NAME ":" type)? "):" block
return_statement: "return" expr _NL
assignment: NAME "=" expr _NL
array_assignment: NAME ("[" expr ("," expr)* "]")+ "=" expr _NL
!if_block: "if" expr ":" block ("elseif" expr ":" block)* ("else" ":" block)?
for_block: "for" NAME "=" expr "->" expr ":" block
import: "import" NAME _NL -> import_
from_import: "from" NAME "import" NAME ("," NAME)*
!comment: ("#" | "//") /[^\n]+/x _NL
?expr: string
| number
| identifier
| array_access
| func_call
| binary_operation
| paren_expr
string: STRING
number: NUMBER
identifier: NAME
array_access: NAME ("[" expr ("," expr)* "]")+
func_call: NAME "(" ((expr ",")* expr)? ")"
binary_operation: expr binary_operator expr
paren_expr: "(" expr ")"
!binary_operator: "+"
| "-"
| "/"
| "*"
| "%"
| ">"
| ">="
| "<"
| "<="
| "=="
| "||"
| "&&"
| "|"
| "&"
!type: "Int" -> type_ | "Array" -> type_
?block: _NL indent statement+ dedent
indent: _INDENT -> indent_
dedent: _DEDENT
%import common.CNAME -> NAME
%import common.ESCAPED_STRING -> STRING
%import common.NUMBER
%import common.WS_INLINE
%declare _INDENT _DEDENT
%ignore WS_INLINE
_NL: /\r?\n( )*/
blank_line: _NL
//%import common.NEWLINE -> _NL