Skip to content

Commit 12ee312

Browse files
authored
Include the line end in spans of Messages and Terms (#258)
This is similar to the change made to Comments except here it doesn't affect the values, just the spans. The EBNF defines Message and Term as: Message ::= Comment? Identifier inline_space? "=" inline_space? ((Pattern Attribute*) | (Attribute+)) line_end Term ::= Comment? TermIdentifier inline_space? "=" inline_space? Value Attribute* line_end
1 parent 3f0cd3e commit 12ee312

16 files changed

+59
-48
lines changed

fluent-syntax/src/ftlstream.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ export class FTLParserStream extends ParserStream {
8484
this.skipInlineWS();
8585
}
8686

87+
expectLineEnd() {
88+
if (this.ch) {
89+
return this.expectChar("\n");
90+
}
91+
92+
// EOF is a valid line end in Fluent.
93+
return true;
94+
}
95+
8796
takeChar(f) {
8897
const ch = this.ch;
8998
if (ch !== undefined && f(ch)) {

fluent-syntax/src/parser.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ export default class FluentParser {
241241
throw new ParseError("E0005", id.name);
242242
}
243243

244+
ps.expectLineEnd();
244245
return new AST.Message(id, pattern, attrs);
245246
}
246247

@@ -261,6 +262,7 @@ export default class FluentParser {
261262
var attrs = this.getAttributes(ps);
262263
}
263264

265+
ps.expectLineEnd();
264266
return new AST.Term(id, value, attrs);
265267
}
266268

fluent-syntax/test/fixtures_structure/elements_indent.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"span": {
3838
"type": "Span",
3939
"start": 0,
40-
"end": 9
40+
"end": 10
4141
}
4242
},
4343
{
@@ -135,7 +135,7 @@
135135
"span": {
136136
"type": "Span",
137137
"start": 28,
138-
"end": 61
138+
"end": 62
139139
}
140140
},
141141
{

fluent-syntax/test/fixtures_structure/escape_sequences.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"span": {
3838
"type": "Span",
3939
"start": 0,
40-
"end": 48
40+
"end": 49
4141
}
4242
},
4343
{
@@ -76,7 +76,7 @@
7676
"span": {
7777
"type": "Span",
7878
"start": 49,
79-
"end": 97
79+
"end": 98
8080
}
8181
},
8282
{
@@ -115,7 +115,7 @@
115115
"span": {
116116
"type": "Span",
117117
"start": 98,
118-
"end": 121
118+
"end": 122
119119
}
120120
},
121121
{
@@ -154,7 +154,7 @@
154154
"span": {
155155
"type": "Span",
156156
"start": 122,
157-
"end": 147
157+
"end": 148
158158
}
159159
},
160160
{
@@ -211,7 +211,7 @@
211211
"span": {
212212
"type": "Span",
213213
"start": 171,
214-
"end": 195
214+
"end": 196
215215
}
216216
},
217217
{
@@ -258,7 +258,7 @@
258258
"span": {
259259
"type": "Span",
260260
"start": 196,
261-
"end": 224
261+
"end": 225
262262
}
263263
},
264264
{

fluent-syntax/test/fixtures_structure/expressions_call_args.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
"span": {
109109
"type": "Span",
110110
"start": 0,
111-
"end": 43
111+
"end": 44
112112
}
113113
}
114114
],

fluent-syntax/test/fixtures_structure/leading_dots.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"span": {
3838
"type": "Span",
3939
"start": 0,
40-
"end": 14
40+
"end": 15
4141
}
4242
},
4343
{
@@ -76,7 +76,7 @@
7676
"span": {
7777
"type": "Span",
7878
"start": 15,
79-
"end": 29
79+
"end": 30
8080
}
8181
},
8282
{
@@ -132,7 +132,7 @@
132132
"span": {
133133
"type": "Span",
134134
"start": 30,
135-
"end": 48
135+
"end": 49
136136
}
137137
},
138138
{
@@ -188,7 +188,7 @@
188188
"span": {
189189
"type": "Span",
190190
"start": 49,
191-
"end": 71
191+
"end": 72
192192
}
193193
},
194194
{
@@ -253,7 +253,7 @@
253253
"span": {
254254
"type": "Span",
255255
"start": 73,
256-
"end": 105
256+
"end": 106
257257
}
258258
},
259259
{
@@ -318,7 +318,7 @@
318318
"span": {
319319
"type": "Span",
320320
"start": 107,
321-
"end": 140
321+
"end": 141
322322
}
323323
},
324324
{
@@ -478,7 +478,7 @@
478478
"span": {
479479
"type": "Span",
480480
"start": 350,
481-
"end": 414
481+
"end": 415
482482
}
483483
},
484484
{
@@ -534,7 +534,7 @@
534534
"span": {
535535
"type": "Span",
536536
"start": 416,
537-
"end": 484
537+
"end": 485
538538
}
539539
},
540540
{
@@ -592,7 +592,7 @@
592592
"span": {
593593
"type": "Span",
594594
"start": 486,
595-
"end": 516
595+
"end": 517
596596
}
597597
},
598598
{
@@ -650,7 +650,7 @@
650650
"span": {
651651
"type": "Span",
652652
"start": 522,
653-
"end": 553
653+
"end": 554
654654
}
655655
},
656656
{
@@ -725,7 +725,7 @@
725725
"span": {
726726
"type": "Span",
727727
"start": 555,
728-
"end": 599
728+
"end": 600
729729
}
730730
},
731731
{
@@ -873,7 +873,7 @@
873873
"span": {
874874
"type": "Span",
875875
"start": 601,
876-
"end": 685
876+
"end": 686
877877
}
878878
},
879879
{

fluent-syntax/test/fixtures_structure/message_with_empty_pattern.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
"span": {
115115
"type": "Span",
116116
"start": 346,
117-
"end": 369
117+
"end": 370
118118
}
119119
},
120120
{
@@ -172,7 +172,7 @@
172172
"span": {
173173
"type": "Span",
174174
"start": 371,
175-
"end": 395
175+
"end": 396
176176
}
177177
},
178178
{

fluent-syntax/test/fixtures_structure/multiline-comment.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"span": {
4848
"type": "Span",
4949
"start": 50,
50-
"end": 61
50+
"end": 62
5151
}
5252
}
5353
],

fluent-syntax/test/fixtures_structure/placeable_at_eol.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"span": {
7272
"type": "Span",
7373
"start": 0,
74-
"end": 131
74+
"end": 132
7575
}
7676
},
7777
{
@@ -135,7 +135,7 @@
135135
"span": {
136136
"type": "Span",
137137
"start": 133,
138-
"end": 184
138+
"end": 185
139139
}
140140
},
141141
{
@@ -199,7 +199,7 @@
199199
"span": {
200200
"type": "Span",
201201
"start": 186,
202-
"end": 234
202+
"end": 235
203203
}
204204
}
205205
],

fluent-syntax/test/fixtures_structure/simple_message.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"span": {
3838
"type": "Span",
3939
"start": 0,
40-
"end": 9
40+
"end": 10
4141
}
4242
}
4343
],

fluent-syntax/test/fixtures_structure/sparse-messages.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"span": {
3838
"type": "Span",
3939
"start": 0,
40-
"end": 17
40+
"end": 18
4141
}
4242
},
4343
{
@@ -95,7 +95,7 @@
9595
"span": {
9696
"type": "Span",
9797
"start": 19,
98-
"end": 49
98+
"end": 50
9999
}
100100
},
101101
{
@@ -171,7 +171,7 @@
171171
"span": {
172172
"type": "Span",
173173
"start": 52,
174-
"end": 127
174+
"end": 128
175175
}
176176
},
177177
{
@@ -210,7 +210,7 @@
210210
"span": {
211211
"type": "Span",
212212
"start": 130,
213-
"end": 144
213+
"end": 145
214214
}
215215
},
216216
{
@@ -349,7 +349,7 @@
349349
"span": {
350350
"type": "Span",
351351
"start": 146,
352-
"end": 209
352+
"end": 210
353353
}
354354
},
355355
{
@@ -416,7 +416,7 @@
416416
"span": {
417417
"type": "Span",
418418
"start": 211,
419-
"end": 252
419+
"end": 253
420420
}
421421
},
422422
{
@@ -483,7 +483,7 @@
483483
"span": {
484484
"type": "Span",
485485
"start": 254,
486-
"end": 294
486+
"end": 295
487487
}
488488
}
489489
],

fluent-syntax/test/fixtures_structure/standalone_comment.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"span": {
3838
"type": "Span",
3939
"start": 0,
40-
"end": 11
40+
"end": 12
4141
}
4242
},
4343
{

fluent-syntax/test/fixtures_structure/term.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
"span": {
140140
"type": "Span",
141141
"start": 0,
142-
"end": 108
142+
"end": 109
143143
}
144144
},
145145
{
@@ -229,7 +229,7 @@
229229
"span": {
230230
"type": "Span",
231231
"start": 110,
232-
"end": 171
232+
"end": 172
233233
}
234234
},
235235
{
@@ -506,7 +506,7 @@
506506
"span": {
507507
"type": "Span",
508508
"start": 173,
509-
"end": 437
509+
"end": 438
510510
}
511511
}
512512
],

fluent-syntax/test/fixtures_structure/variant_with_empty_pattern.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
"span": {
101101
"type": "Span",
102102
"start": 0,
103-
"end": 42
103+
"end": 43
104104
}
105105
}
106106
],

0 commit comments

Comments
 (0)