-
Notifications
You must be signed in to change notification settings - Fork 0
/
lang.tr
70 lines (57 loc) · 2.42 KB
/
lang.tr
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
# -*- Mode: peg; -*-
Module <- { "Module" ({ Statement+ } / Statement)? }
Code <- { "Code" ({ Statement+ } / Statement)? }
CodeSingle <- { "Code" { "Statement" Expression } }
FunCode <- CodeSingle / Code
# Statements & Expression Types
Statement <- { "Statement" (Assignment / IfStm / WhileStm / ForStm / TryStm / ThrowStm / Function / ReturnStm / ExprStm / Break / Continue) }
Assignment <- { "Assignment" { Expression (Store / StoreLex) } }
ExprStm <- Expression
WhileStm <- { "WhileStm" { Expression Code } }
ForStm <- { "ForStm" { Store Expression Code } }
Break <- "break"
Continue <- "continue"
IfStm <- { "IfStm" { Expression Code Code? } }
ThrowStm <- { "ThrowStm" Expression }
ReturnStm <- { "ReturnStm" Expression }
TryStm <- { "TryStm" { Code CatchStm } }
CatchStm <- { "CatchStm" { Load Store Code } }
Expression <- Attribute / Logical / BinOp / Comparison / Call / Access / Lambda / Load / Unary / Value
# Logical Operators
Logical <- { "Logical" { Expression (LogicalTwo / LogicalMult) } }
LogicalTwo <- { LogicalOp LogicalRd }
LogicalMult<- { { LogicalOp LogicalRd }+ }
LogicalOp <- Atom
LogicalRd <- Expression
BinOp <- { "BinOp" Expression Atom Expression }
Comparison <- { "Comparison" Expression Atom Expression }
Unary <- { "Unary" { Atom Expression } }
Attribute <- { "Attribute" { Expression (LoadAttr / MethodCall)+ } }
LoadAttr <- { "LoadAttr" Atom }
LoadMethod <- { "LoadMethod" Atom }
MethodCall <- { "MethodCall" { LoadMethod CallParams } }
ScopeId <- { "ScopeId" Atom }
Lambda <- { "Lambda" { Params FunCode } }
/ { "Lambda" { ScopeId Params FunCode } }
Function <- { "Function" { Atom Params FunCode } }
/ { "Function" { ScopeId Atom Params FunCode } }
# Callable Parameter rules
Params <- { "Params" { Param+ }? }
Param <- { "Param" Atom }
# Call Site rules
Call <- { "Call" { Expression CallParams } }
CallParams <- { Expression+ }?
# Child access
Access <- { "Access" { Expression (Expression / Slice) } }
Slice <- { "Slice" { Expression Expression } }
# Value rules
Value <- { "Value" (Number / String / Boolean / List / Null) }
Number <- { "Number" Atom }
String <- { "String" Atom }
Boolean <- { "BOOL" Atom }
List <- { "List" { Expression* }? }
Null <- "null"
Load <- { "Load" Atom }
Store <- { "Store" Atom }
StoreLex <- { "StoreLex" Atom }
Atom <- !{ .* } .