-
Notifications
You must be signed in to change notification settings - Fork 16
/
dynaml.peg
137 lines (108 loc) · 4.47 KB
/
dynaml.peg
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package dynaml
type DynamlGrammar Peg {}
Dynaml <- (Prefer / MarkedExpression / Expression) !.
Prefer <- ws 'prefer' req_ws Expression
MarkedExpression <- ws Marker ( req_ws SubsequentMarker )* ws MarkerExpression ? ws
SubsequentMarker <- Marker
Marker <- '&' ( 'template' / 'temporary' / 'local' / 'inject' / 'state' / 'default' / 'dynamic' / TagMarker )
TagMarker <- 'tag:' '*'? Tag
MarkerExpression <- Grouped
Expression <- ( Scoped / LambdaExpr / Level7 ) ws
Scoped <- ws Scope ws Expression
Scope <- CreateScope ws Assignments? ')'
CreateScope <- '('
Level7 <- ws Level6 ( req_ws Or )*
Or <- OrOp req_ws Level6
OrOp <- '||' / '//'
Level6 <- Conditional / Level5
Conditional <- Level5 ws '?' Expression ':' Expression
Level5 <- Level4 ( Concatenation )*
Concatenation <- req_ws Level4
Level4 <- Level3 ( req_ws ( LogOr / LogAnd ) )*
LogOr <- '-or' req_ws Level3
LogAnd <- '-and' req_ws Level3
Level3 <- Level2 ( req_ws Comparison )*
Comparison <- CompareOp req_ws Level2
CompareOp <- '==' / '!=' / '<=' / '>=' / '>' / '<' / '>'
Level2 <- Level1 ( req_ws ( Addition / Subtraction ) )*
Addition <- '+' req_ws Level1
Subtraction <- '-' req_ws Level1
Level1 <- Level0 ( req_ws ( Multiplication / Division / Modulo ) )*
Multiplication <- '*' req_ws Level0
Division <- '/' req_ws Level0
Modulo <- '%' req_ws Level0
Level0 <- IP / String / Number / Boolean / Undefined / Nil / Symbol / Not /
Substitution / Merge / Auto / Lambda / Chained
Chained <- ( MapMapping / Sync / Catch / Mapping / MapSelection / Selection / Sum / List / Map / Range / Grouped / Reference / TopIndex ) ChainedQualifiedExpression*
ChainedQualifiedExpression <- ChainedCall / Currying / ChainedRef / ChainedDynRef / Projection
ChainedRef <- PathComponent FollowUpRef
ChainedDynRef <- '.'? Indices
TopIndex <- '.' Indices
Indices <- StartList ExpressionList ']'
Slice <- Range
Currying <- '*' ChainedCall
ChainedCall <- StartArguments NameArgumentList? ')'
StartArguments <- '(' ws
NameArgumentList <- (( NextNameArgument ( ',' NextNameArgument)* ) / NextExpression) ( ',' NextExpression)*
NextNameArgument <- ws Name ws '=' ws Expression ws
ExpressionList <- NextExpression ( ',' NextExpression)*
NextExpression <- Expression ListExpansion?
ListExpansion <- '...' ws
Projection <- '.'? ( '[*]' / Slice ) ProjectionValue ChainedQualifiedExpression*
ProjectionValue <- {}
Substitution <- '*' Level0
Not <- '!' ws Level0
Grouped <- '(' Expression ')'
Range <- StartRange Expression? RangeOp Expression? ']'
StartRange <- '['
RangeOp <- '..'
Number <- '-'? [0-9] [0-9_]* ( '.' [0-9] [0-9]* )? ( ( 'e' / 'E' ) '-'? [0-9] [0-9]* )? !'::'
String <- '"' ('\\"' / !'"' .)* '"'
Boolean <- 'true' / 'false'
Nil <- 'nil' / '~'
Undefined <- '~~'
Symbol <- '$' Name
List <- StartList ExpressionList? ']'
StartList <- '[' ws
Map <- CreateMap ws Assignments? '}'
CreateMap <- '{'
Assignments <- Assignment (',' Assignment)*
Assignment <- Expression '=' Expression
Merge <- RefMerge / SimpleMerge
RefMerge <- 'merge' !( req_ws Required ) ( req_ws (Replace / On ))? req_ws Reference
SimpleMerge <- 'merge' !'(' ( req_ws (Replace/Required/On) )?
Replace <- 'replace'
Required <- 'required'
On <- 'on' req_ws Name
Auto <- 'auto'
Default <- {}
Sync <- 'sync[' Level7 (( (LambdaExpr LambdaExt) / (LambdaOrExpr LambdaOrExpr)) (( '|' Expression) / Default ) / (LambdaOrExpr Default Default)) ']'
LambdaExt <- ',' Expression
LambdaOrExpr <- LambdaExpr / ( '|' Expression )
Catch <- 'catch[' Level7 LambdaOrExpr ']'
MapMapping <- 'map{' Level7 LambdaOrExpr '}'
Mapping <- 'map[' Level7 LambdaOrExpr ']'
MapSelection <- 'select{' Level7 LambdaOrExpr '}'
Selection <- 'select[' Level7 LambdaOrExpr ']'
Sum <- 'sum[' Level7 '|' Level7 LambdaOrExpr ']'
Lambda <- 'lambda' ( LambdaRef / LambdaExpr )
LambdaRef <- req_ws Expression
LambdaExpr <- ws Params ws '->' Expression
Params <- '|' StartParams ws Names? '|'
StartParams <- {}
Names <- NextName (',' NextName)* DefaultValue? (',' NextName DefaultValue )* VarParams?
NextName <- ws Name ws
Name <- [a-zA-Z0-9_]+
DefaultValue <- '=' Expression
VarParams <- '...' ws
Reference <- (( TagPrefix ('.' / Key )) / ( '.'? Key )) FollowUpRef
TagPrefix <- ( ('doc' [.:] '-'? [0-9]+) / Tag ) '::'
Tag <- TagComponent ( [.:] TagComponent )*
TagComponent <- [a-zA-Z_] [a-zA-Z0-9_]*
FollowUpRef <- PathComponent*
PathComponent <- ( '.' Key ) / ( '.'? Index )
Key <- [a-zA-Z0-9_] [a-zA-Z0-9_\-]* ( ':' [a-zA-Z0-9_] [a-zA-Z0-9_\-]* )?
Index <- '[' '-'? [0-9]+ ']'
IP <- [0-9]+ '.' [0-9]+ '.' [0-9]+ '.' [0-9]+
ws <- [ \t\n\r]*
req_ws <- [ \t\n\r]+