forked from cloudfoundry-incubator/spiff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dynaml.peg
60 lines (40 loc) · 1.48 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
package dynaml
type DynamlGrammar Peg {}
Dynaml <- (Prefer / Expression) !.
Prefer <- ws 'prefer' req_ws Expression
Expression <- ws Level4 ws
Level4 <- Level3 ( req_ws Or )*
Or <- '||' req_ws Level3
Level3 <- Level2 ( Concatenation )*
Concatenation <- req_ws Level2
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 <- Grouped / Call / Boolean / Nil / String / Integer / List / Merge / Auto / Mapping / Reference
Grouped <- '(' Expression ')'
Call <- Name '(' Arguments ')'
Name <- [a-zA-Z0-9_]+
Arguments <- Expression (NextExpression)*
NextExpression <- ',' Expression
Integer <- '-'? [0-9_]+
String <- '"' ('\\"' / !'"' .)* '"'
Boolean <- 'true' / 'false'
Nil <- 'nil' / '~'
List <- '[' Contents? ']'
Contents <- Expression (NextExpression)*
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'
Mapping <- 'map[' Expression '|' ws Name ( ws ',' ws Name)? ws '|' ws '->' Expression ']'
Reference <- '.'? Key ('.' Key / '.' '[' [0-9]+ ']')*
Key <- [a-zA-Z0-9_] [a-zA-Z0-9_\-]* ( ':' [a-zA-Z0-9_] [a-zA-Z0-9_\-]* )?
ws <- [ \t\n\r]*
req_ws <- [ \t\n\r]+