Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit df90657

Browse files
committed
formatting and tweaks
1 parent 675b7d4 commit df90657

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

lib/snippet-body.pegjs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,99 +11,99 @@ innerBodyContent = content:(tabstop / choice / variable / nonCloseBraceText)* {
1111
tabstop = simpleTabstop / tabstopWithoutPlaceholder / tabstopWithPlaceholder / tabstopWithTransform
1212

1313
simpleTabstop = '$' index:int {
14-
return { index: makeInteger(index), content: [] }
14+
return { index: makeInteger(index), content: [] }
1515
}
1616

1717
tabstopWithoutPlaceholder = '${' index:int '}' {
18-
return { index: makeInteger(index), content: [] }
18+
return { index: makeInteger(index), content: [] }
1919
}
2020

2121
tabstopWithPlaceholder = '${' index:int ':' content:innerBodyContent '}' {
22-
return { index: makeInteger(index), content: content }
22+
return { index: makeInteger(index), content: content }
2323
}
2424

2525
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+
}
3131
}
3232

3333
choice = '${' index:int '|' choice:choicecontents '|}' {
34-
return { index: makeInteger(index), choice: choice }
34+
return { index: makeInteger(index), choice: choice }
3535
}
3636

3737
choicecontents = elem:choicetext rest:(',' val:choicetext { return val } )* {
38-
return [elem, ...rest]
38+
return [elem, ...rest]
3939
}
4040

4141
choicetext = choicetext:(choiceEscaped / [^|,] / barred:('|' &[^}]) { return barred.join('') } )+ {
42-
return choicetext.join('')
42+
return choicetext.join('')
4343
}
4444

4545
// Transform is applied when tabbed off
4646
transform = '/' regex:regex '/' replace:replace '/' flags:flags {
47-
return { regex: regex, format: replace, flags: flags }
47+
return { regex: regex, format: replace, flags: flags }
4848
}
4949

5050
regex = regex:(escaped / [^/])* {
51-
return new RegExp(regex.join(''))
51+
return new RegExp(regex.join(''))
5252
}
5353

5454
replace = (format / replacetext)*
5555

56-
// TODO: Format with conditionals on match
56+
// TODO: Support conditionals
5757
format = simpleFormat / formatWithoutPlaceholder / formatWithCaseTransform
5858

5959
simpleFormat = '$' index:int {
60-
return { index: makeInteger(index) }
60+
return { index: makeInteger(index) }
6161
}
6262

6363
formatWithoutPlaceholder = '${' index:int '}' {
64-
return { index: makeInteger(index) }
64+
return { index: makeInteger(index) }
6565
}
6666

6767
formatWithCaseTransform = '${' index:int ':' casetransform:casetransform '}' {
68-
return { index: makeInteger(index), transform: casetransform }
68+
return { index: makeInteger(index), transform: casetransform }
6969
}
7070

7171
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':
7575
case 'downcase':
7676
case 'capitalize':
77-
return type
77+
return type
7878
default:
79-
return 'none'
79+
return 'none'
8080
}
8181
}
8282

8383
replacetext = replacetext:(escaped / !format char:[^/] { return char })+ {
84-
return replacetext.join('')
84+
return replacetext.join('')
8585
}
8686

8787
variable = simpleVariable / variableWithoutPlaceholder / variableWithPlaceholder / variableWithTransform
8888

8989
simpleVariable = '$' name:variableName {
90-
return { variable: name }
90+
return { variable: name }
9191
}
9292

9393
variableWithoutPlaceholder = '${' name:variableName '}' {
94-
return { variable: name }
94+
return { variable: name }
9595
}
9696

9797
variableWithPlaceholder = '${' name:variableName ':' content:innerBodyContent '}' {
9898
return { variable: name, content: content }
9999
}
100100

101101
variableWithTransform = '${' name:variableName substitution:transform '}' {
102-
return { variable: name, substitution: substitution }
102+
return { variable: name, substitution: substitution }
103103
}
104104

105105
variableName = first:[a-zA-Z_] rest:[a-zA-Z_0-9]* {
106-
return first + rest.join('')
106+
return first + rest.join('')
107107
}
108108

109109
int = [0-9]+
@@ -112,7 +112,7 @@ escaped = '\\' char:. {
112112
switch (char) {
113113
case '$':
114114
case '\\':
115-
case '\x7D':
115+
case '\x7D': // back brace; PEGjs would treat it as the JS scope end though
116116
return char
117117
default:
118118
return '\\' + char
@@ -132,13 +132,13 @@ choiceEscaped = '\\' char:. {
132132
}
133133
}
134134

135-
token = escaped / !tabstop !tabstopWithPlaceholder !variable !choice char:. { return char }
136-
137135
flags = flags:[a-z]* {
138-
return flags.join('') + 'g'
136+
return flags.join('') + 'g'
139137
}
140138

141-
text = text:token+ { return text.join('') }
139+
text = text:(escaped / !tabstop !tabstopWithPlaceholder !variable !choice char:. { return char })+ {
140+
return text.join('')
141+
}
142142

143143
nonCloseBraceText = text:(escaped / !tabstop !tabstopWithPlaceholder !variable !choice char:[^}] { return char })+ {
144144
return text.join('')

0 commit comments

Comments
 (0)