File tree 11 files changed +212
-55
lines changed 11 files changed +212
-55
lines changed Original file line number Diff line number Diff line change @@ -77,18 +77,14 @@ SelectExpression ::= InlineExpression blank? "->" blank_inline? variant_list
77
77
variant_list ::= Variant * DefaultVariant Variant * line_end
78
78
Variant ::= line_end blank ? VariantKey blank_inline ? Value
79
79
DefaultVariant ::= line_end blank ? " *" VariantKey blank_inline ? Value
80
- VariantKey ::= " [" blank ? (NumberLiteral | VariantName ) blank ? " ]"
81
- VariantName ::= word (blank word )*
80
+ VariantKey ::= " [" blank ? (NumberLiteral | Identifier ) blank ? " ]"
82
81
83
82
/* Identifiers */
84
83
Identifier ::= identifier
85
84
TermIdentifier ::= " -" identifier
86
85
VariableIdentifier ::= " $" identifier
87
86
Function ::= [A-Z ] [A-Z_ ? - ]*
88
-
89
- /* Tokens */
90
87
identifier ::= [a-zA-Z ] [a-zA-Z0-9_- ]*
91
- word ::= (regular_char - backslash - " }" - " {" - " ]" - " [" - " =" )+
92
88
93
89
/* Characters */
94
90
backslash ::= " \\"
Original file line number Diff line number Diff line change @@ -194,13 +194,6 @@ export class Identifier extends SyntaxNode {
194
194
}
195
195
}
196
196
197
- export class VariantName extends Identifier {
198
- constructor ( name ) {
199
- super ( name ) ;
200
- this . type = "VariantName" ;
201
- }
202
- }
203
-
204
197
export class BaseComment extends Entry {
205
198
constructor ( content ) {
206
199
super ( ) ;
Original file line number Diff line number Diff line change @@ -335,22 +335,11 @@ let VariantKey = defer(() =>
335
335
maybe ( blank ) ,
336
336
either (
337
337
NumberLiteral ,
338
- VariantName ) ,
338
+ Identifier ) ,
339
339
maybe ( blank ) ,
340
340
string ( "]" ) )
341
341
. map ( element_at ( 2 ) ) ) ;
342
342
343
- let VariantName = defer ( ( ) =>
344
- sequence (
345
- word ,
346
- repeat (
347
- sequence (
348
- blank ,
349
- word ) ) )
350
- . map ( flatten ( 2 ) )
351
- . map ( join )
352
- . chain ( into ( FTL . VariantName ) ) ) ;
353
-
354
343
/* ----------- */
355
344
/* Identifiers */
356
345
@@ -380,8 +369,6 @@ let Function =
380
369
. map ( join )
381
370
. chain ( into ( FTL . Function ) ) ;
382
371
383
- /* ------ */
384
- /* Tokens */
385
372
let identifier =
386
373
sequence (
387
374
charset ( "a-zA-Z" ) ,
@@ -390,18 +377,6 @@ let identifier =
390
377
. map ( flatten ( 1 ) )
391
378
. map ( join ) ;
392
379
393
- let word = defer ( ( ) =>
394
- repeat1 (
395
- and (
396
- not ( string ( "=" ) ) ,
397
- not ( string ( "[" ) ) ,
398
- not ( string ( "]" ) ) ,
399
- not ( string ( "{" ) ) ,
400
- not ( string ( "}" ) ) ,
401
- not ( backslash ) ,
402
- regular_char ) )
403
- . map ( join ) ) ;
404
-
405
380
/* ---------- */
406
381
/* Characters */
407
382
Original file line number Diff line number Diff line change 350
350
{
351
351
"type" : " Variant" ,
352
352
"key" : {
353
- "type" : " VariantName " ,
353
+ "type" : " Identifier " ,
354
354
"name" : " one"
355
355
},
356
356
"value" : {
367
367
{
368
368
"type" : " Variant" ,
369
369
"key" : {
370
- "type" : " VariantName " ,
370
+ "type" : " Identifier " ,
371
371
"name" : " other"
372
372
},
373
373
"value" : {
Original file line number Diff line number Diff line change 22
22
}
23
23
},
24
24
"key" : {
25
- "type" : " VariantName " ,
25
+ "type" : " Identifier " ,
26
26
"name" : " case"
27
27
}
28
28
}
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ new-messages =
6
6
7
7
valid-selector =
8
8
{ -term .case ->
9
- *[ many words ] value
9
+ *[ key ] value
10
10
}
11
11
12
12
# ERROR
Original file line number Diff line number Diff line change 44
44
{
45
45
"type" : " Variant" ,
46
46
"key" : {
47
- "type" : " VariantName " ,
47
+ "type" : " Identifier " ,
48
48
"name" : " other"
49
49
},
50
50
"value" : {
104
104
{
105
105
"type" : " Variant" ,
106
106
"key" : {
107
- "type" : " VariantName " ,
108
- "name" : " many words "
107
+ "type" : " Identifier " ,
108
+ "name" : " key "
109
109
},
110
110
"value" : {
111
111
"type" : " Pattern" ,
156
156
{
157
157
"type" : " Variant" ,
158
158
"key" : {
159
- "type" : " VariantName " ,
159
+ "type" : " Identifier " ,
160
160
"name" : " one"
161
161
},
162
162
"value" : {
202
202
{
203
203
"type" : " Variant" ,
204
204
"key" : {
205
- "type" : " VariantName " ,
205
+ "type" : " Identifier " ,
206
206
"name" : " one"
207
207
},
208
208
"value" : {
220
220
{
221
221
"type" : " Variant" ,
222
222
"key" : {
223
- "type" : " VariantName " ,
223
+ "type" : " Identifier " ,
224
224
"name" : " two"
225
225
},
226
226
"value" : {
Original file line number Diff line number Diff line change 120
120
{
121
121
"type" : " Variant" ,
122
122
"key" : {
123
- "type" : " VariantName " ,
123
+ "type" : " Identifier " ,
124
124
"name" : " one"
125
125
},
126
126
"value" : {
137
137
{
138
138
"type" : " Variant" ,
139
139
"key" : {
140
- "type" : " VariantName " ,
140
+ "type" : " Identifier " ,
141
141
"name" : " two"
142
142
},
143
143
"value" : {
Original file line number Diff line number Diff line change
1
+ -simple-identifier =
2
+ {
3
+ *[key] value
4
+ }
5
+
6
+ -identifier-surrounded-by-whitespace =
7
+ {
8
+ *[ key ] value
9
+ }
10
+
11
+ -int-number =
12
+ {
13
+ *[1] value
14
+ }
15
+
16
+ -float-number =
17
+ {
18
+ *[3.14] value
19
+ }
20
+
21
+ # ERROR
22
+ -invalid-identifier =
23
+ {
24
+ *[two words] value
25
+ }
26
+
27
+ # ERROR
28
+ -invalid-int =
29
+ {
30
+ *[1 apple] value
31
+ }
32
+
33
+ # ERROR
34
+ -invalid-int =
35
+ {
36
+ *[3.14 apples] value
37
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "type" : " Resource" ,
3
+ "body" : [
4
+ {
5
+ "type" : " Term" ,
6
+ "id" : {
7
+ "type" : " Identifier" ,
8
+ "name" : " -simple-identifier"
9
+ },
10
+ "value" : {
11
+ "type" : " VariantList" ,
12
+ "variants" : [
13
+ {
14
+ "type" : " Variant" ,
15
+ "key" : {
16
+ "type" : " Identifier" ,
17
+ "name" : " key"
18
+ },
19
+ "value" : {
20
+ "type" : " Pattern" ,
21
+ "elements" : [
22
+ {
23
+ "type" : " TextElement" ,
24
+ "value" : " value"
25
+ }
26
+ ]
27
+ },
28
+ "default" : true
29
+ }
30
+ ]
31
+ },
32
+ "attributes" : [],
33
+ "comment" : null
34
+ },
35
+ {
36
+ "type" : " Term" ,
37
+ "id" : {
38
+ "type" : " Identifier" ,
39
+ "name" : " -identifier-surrounded-by-whitespace"
40
+ },
41
+ "value" : {
42
+ "type" : " VariantList" ,
43
+ "variants" : [
44
+ {
45
+ "type" : " Variant" ,
46
+ "key" : {
47
+ "type" : " Identifier" ,
48
+ "name" : " key"
49
+ },
50
+ "value" : {
51
+ "type" : " Pattern" ,
52
+ "elements" : [
53
+ {
54
+ "type" : " TextElement" ,
55
+ "value" : " value"
56
+ }
57
+ ]
58
+ },
59
+ "default" : true
60
+ }
61
+ ]
62
+ },
63
+ "attributes" : [],
64
+ "comment" : null
65
+ },
66
+ {
67
+ "type" : " Term" ,
68
+ "id" : {
69
+ "type" : " Identifier" ,
70
+ "name" : " -int-number"
71
+ },
72
+ "value" : {
73
+ "type" : " VariantList" ,
74
+ "variants" : [
75
+ {
76
+ "type" : " Variant" ,
77
+ "key" : {
78
+ "type" : " NumberLiteral" ,
79
+ "value" : " 1"
80
+ },
81
+ "value" : {
82
+ "type" : " Pattern" ,
83
+ "elements" : [
84
+ {
85
+ "type" : " TextElement" ,
86
+ "value" : " value"
87
+ }
88
+ ]
89
+ },
90
+ "default" : true
91
+ }
92
+ ]
93
+ },
94
+ "attributes" : [],
95
+ "comment" : null
96
+ },
97
+ {
98
+ "type" : " Term" ,
99
+ "id" : {
100
+ "type" : " Identifier" ,
101
+ "name" : " -float-number"
102
+ },
103
+ "value" : {
104
+ "type" : " VariantList" ,
105
+ "variants" : [
106
+ {
107
+ "type" : " Variant" ,
108
+ "key" : {
109
+ "type" : " NumberLiteral" ,
110
+ "value" : " 3.14"
111
+ },
112
+ "value" : {
113
+ "type" : " Pattern" ,
114
+ "elements" : [
115
+ {
116
+ "type" : " TextElement" ,
117
+ "value" : " value"
118
+ }
119
+ ]
120
+ },
121
+ "default" : true
122
+ }
123
+ ]
124
+ },
125
+ "attributes" : [],
126
+ "comment" : null
127
+ },
128
+ {
129
+ "type" : " Comment" ,
130
+ "content" : " ERROR"
131
+ },
132
+ {
133
+ "type" : " Junk" ,
134
+ "annotations" : [],
135
+ "content" : " -invalid-identifier =\n {\n *[two words] value\n }\n "
136
+ },
137
+ {
138
+ "type" : " Comment" ,
139
+ "content" : " ERROR"
140
+ },
141
+ {
142
+ "type" : " Junk" ,
143
+ "annotations" : [],
144
+ "content" : " -invalid-int =\n {\n *[1 apple] value\n }\n "
145
+ },
146
+ {
147
+ "type" : " Comment" ,
148
+ "content" : " ERROR"
149
+ },
150
+ {
151
+ "type" : " Junk" ,
152
+ "annotations" : [],
153
+ "content" : " -invalid-int =\n {\n *[3.14 apples] value\n }\n "
154
+ }
155
+ ]
156
+ }
You can’t perform that action at this time.
0 commit comments