@@ -11,99 +11,99 @@ innerBodyContent = content:(tabstop / choice / variable / nonCloseBraceText)* {
11
11
tabstop = simpleTabstop / tabstopWithoutPlaceholder / tabstopWithPlaceholder / tabstopWithTransform
12
12
13
13
simpleTabstop = '$' index :int {
14
- return { index: makeInteger (index), content: [] }
14
+ return { index: makeInteger (index), content: [] }
15
15
}
16
16
17
17
tabstopWithoutPlaceholder = '${' index :int '}' {
18
- return { index: makeInteger (index), content: [] }
18
+ return { index: makeInteger (index), content: [] }
19
19
}
20
20
21
21
tabstopWithPlaceholder = '${' index :int ':' content :innerBodyContent '}' {
22
- return { index: makeInteger (index), content: content }
22
+ return { index: makeInteger (index), content: content }
23
23
}
24
24
25
25
tabstopWithTransform = '${' index :int substitution :transform '}' {
26
- return {
27
- index: makeInteger (index),
28
- content: [],
29
- substitution: substitution
30
- }
26
+ return {
27
+ index: makeInteger (index),
28
+ content: [],
29
+ substitution: substitution
30
+ }
31
31
}
32
32
33
33
choice = '${' index :int '|' choice :choicecontents '|}' {
34
- return { index: makeInteger (index), choice: choice }
34
+ return { index: makeInteger (index), choice: choice }
35
35
}
36
36
37
37
choicecontents = elem :choicetext rest :(',' val :choicetext { return val } )* {
38
- return [elem, ... rest]
38
+ return [elem, ... rest]
39
39
}
40
40
41
41
choicetext = choicetext :(choiceEscaped / [^|,] / barred :('|' & [^}]) { return barred .join (' ' ) } )+ {
42
- return choicetext .join (' ' )
42
+ return choicetext .join (' ' )
43
43
}
44
44
45
45
// Transform is applied when tabbed off
46
46
transform = '/' regex :regex '/' replace :replace '/' flags :flags {
47
- return { regex: regex, format: replace, flags: flags }
47
+ return { regex: regex, format: replace, flags: flags }
48
48
}
49
49
50
50
regex = regex :(escaped / [^/])* {
51
- return new RegExp (regex .join (' ' ))
51
+ return new RegExp (regex .join (' ' ))
52
52
}
53
53
54
54
replace = (format / replacetext )*
55
55
56
- // TODO: Format with conditionals on match
56
+ // TODO: Support conditionals
57
57
format = simpleFormat / formatWithoutPlaceholder / formatWithCaseTransform
58
58
59
59
simpleFormat = '$' index :int {
60
- return { index: makeInteger (index) }
60
+ return { index: makeInteger (index) }
61
61
}
62
62
63
63
formatWithoutPlaceholder = '${' index :int '}' {
64
- return { index: makeInteger (index) }
64
+ return { index: makeInteger (index) }
65
65
}
66
66
67
67
formatWithCaseTransform = '${' index :int ':' casetransform :casetransform '}' {
68
- return { index: makeInteger (index), transform: casetransform }
68
+ return { index: makeInteger (index), transform: casetransform }
69
69
}
70
70
71
71
casetransform = '/' type :[a-zA-Z]* {
72
- type = type .join (' ' )
73
- switch (type) {
74
- case ' upcase' :
72
+ type = type .join (' ' )
73
+ switch (type) {
74
+ case ' upcase' :
75
75
case ' downcase' :
76
76
case ' capitalize' :
77
- return type
77
+ return type
78
78
default :
79
- return ' none'
79
+ return ' none'
80
80
}
81
81
}
82
82
83
83
replacetext = replacetext :(escaped / ! format char :[^/] { return char })+ {
84
- return replacetext .join (' ' )
84
+ return replacetext .join (' ' )
85
85
}
86
86
87
87
variable = simpleVariable / variableWithoutPlaceholder / variableWithPlaceholder / variableWithTransform
88
88
89
89
simpleVariable = '$' name :variableName {
90
- return { variable: name }
90
+ return { variable: name }
91
91
}
92
92
93
93
variableWithoutPlaceholder = '${' name :variableName '}' {
94
- return { variable: name }
94
+ return { variable: name }
95
95
}
96
96
97
97
variableWithPlaceholder = '${' name :variableName ':' content :innerBodyContent '}' {
98
98
return { variable: name, content: content }
99
99
}
100
100
101
101
variableWithTransform = '${' name :variableName substitution :transform '}' {
102
- return { variable: name, substitution: substitution }
102
+ return { variable: name, substitution: substitution }
103
103
}
104
104
105
105
variableName = first :[a-zA-Z_] rest :[a-zA-Z_0-9]* {
106
- return first + rest .join (' ' )
106
+ return first + rest .join (' ' )
107
107
}
108
108
109
109
int = [0-9]+
@@ -112,7 +112,7 @@ escaped = '\\' char:. {
112
112
switch (char) {
113
113
case ' $' :
114
114
case ' \\ ' :
115
- case ' \x7D ' :
115
+ case ' \x7D ' : // back brace; PEGjs would treat it as the JS scope end though
116
116
return char
117
117
default :
118
118
return ' \\ ' + char
@@ -132,13 +132,13 @@ choiceEscaped = '\\' char:. {
132
132
}
133
133
}
134
134
135
- token = escaped / ! tabstop ! tabstopWithPlaceholder ! variable ! choice char :. { return char }
136
-
137
135
flags = flags :[a-z]* {
138
- return flags .join (' ' ) + ' g'
136
+ return flags .join (' ' ) + ' g'
139
137
}
140
138
141
- text = text :token + { return text .join (' ' ) }
139
+ text = text :(escaped / ! tabstop ! tabstopWithPlaceholder ! variable ! choice char :. { return char })+ {
140
+ return text .join (' ' )
141
+ }
142
142
143
143
nonCloseBraceText = text :(escaped / ! tabstop ! tabstopWithPlaceholder ! variable ! choice char :[^}] { return char })+ {
144
144
return text .join (' ' )
0 commit comments