Skip to content

Commit bac1271

Browse files
authored
Don't store the term sigil in the identifier name (#183)
1 parent 7a24f9b commit bac1271

15 files changed

+198
-53
lines changed

spec/CHANGELOG.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22

33
## Unreleased
44

5-
- Support astral Unicode characters. (#179)
5+
- Support astral Unicode characters. (#174)
66

77
Unicode characters from outside of the Basic Multilingual Plane can now
88
be used in values of `TextElements` and `StringLiterals`. This means all
99
characters in the U+10000 to U+10FFFF range. 🎉
1010

11+
- Don't store the `-` sigil in `Identifiers` of `Terms`. (#142)
12+
13+
The `-` sigil is no longer part of the term's `Identifier`. This is now
14+
consistent with how `Identifiers` of variables don't include the `$`
15+
sigil either.
16+
1117
## 0.7.0 (October 15, 2018)
1218

1319
- Relax the indentation requirement. (#87)

spec/fluent.ebnf

+4-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Entry ::= (Message line_end)
1212
| (Term line_end)
1313
| CommentLine
1414
Message ::= Identifier blank_inline? "=" blank_inline? ((Pattern Attribute*) | (Attribute+))
15-
Term ::= TermIdentifier blank_inline? "=" blank_inline? Value Attribute*
15+
Term ::= "-" Identifier blank_inline? "=" blank_inline? Value Attribute*
1616

1717
/* Adjacent comment lines of the same comment type are joined together during
1818
* the AST construction. */
@@ -62,8 +62,8 @@ NumberLiteral ::= "-"? digit+ ("." digit+)?
6262

6363
/* Inline Expressions */
6464
MessageReference ::= Identifier
65-
TermReference ::= TermIdentifier
66-
VariableReference ::= VariableIdentifier
65+
TermReference ::= "-" Identifier
66+
VariableReference ::= "$" Identifier
6767
CallExpression ::= Function blank? "(" blank? argument_list blank? ")"
6868
argument_list ::= (Argument blank? "," blank?)* Argument?
6969
Argument ::= NamedArgument
@@ -80,11 +80,8 @@ DefaultVariant ::= line_end blank? "*" VariantKey blank_inline? Value
8080
VariantKey ::= "[" blank? (NumberLiteral | Identifier) blank? "]"
8181

8282
/* Identifiers */
83-
Identifier ::= identifier
84-
TermIdentifier ::= "-" identifier
85-
VariableIdentifier ::= "$" identifier
83+
Identifier ::= [a-zA-Z] [a-zA-Z0-9_-]*
8684
Function ::= [A-Z] [A-Z_?-]*
87-
identifier ::= [a-zA-Z] [a-zA-Z0-9_-]*
8885

8986
/* Characters */
9087
backslash ::= "\\"

syntax/grammar.mjs

+18-25
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ let Message = defer(() =>
5656

5757
let Term = defer(() =>
5858
sequence(
59-
TermIdentifier.abstract,
59+
string("-"),
60+
Identifier.abstract,
6061
maybe(blank_inline),
6162
string("="),
6263
maybe(blank_inline),
@@ -223,10 +224,18 @@ let MessageReference = defer(() =>
223224
Identifier.chain(into(FTL.MessageReference)));
224225

225226
let TermReference = defer(() =>
226-
TermIdentifier.chain(into(FTL.TermReference)));
227+
sequence(
228+
string("-"),
229+
Identifier)
230+
.map(element_at(1))
231+
.chain(into(FTL.TermReference)));
227232

228233
let VariableReference = defer(() =>
229-
VariableIdentifier.chain(into(FTL.VariableReference)));
234+
sequence(
235+
string("$"),
236+
Identifier)
237+
.map(element_at(1))
238+
.chain(into(FTL.VariableReference)));
230239

231240
let CallExpression = defer(() =>
232241
sequence(
@@ -343,22 +352,14 @@ let VariantKey = defer(() =>
343352
/* ----------- */
344353
/* Identifiers */
345354

346-
let Identifier = defer(() =>
347-
identifier.chain(into(FTL.Identifier)));
348-
349-
let TermIdentifier = defer(() =>
355+
let Identifier =
350356
sequence(
351-
string("-"),
352-
identifier)
357+
charset("a-zA-Z"),
358+
repeat(
359+
charset("a-zA-Z0-9_-")))
360+
.map(flatten(1))
353361
.map(join)
354-
.chain(into(FTL.Identifier)));
355-
356-
let VariableIdentifier = defer(() =>
357-
sequence(
358-
string("$"),
359-
identifier)
360-
.map(element_at(1))
361-
.chain(into(FTL.Identifier)));
362+
.chain(into(FTL.Identifier));
362363

363364
let Function =
364365
sequence(
@@ -369,14 +370,6 @@ let Function =
369370
.map(join)
370371
.chain(into(FTL.Function));
371372

372-
let identifier =
373-
sequence(
374-
charset("a-zA-Z"),
375-
repeat(
376-
charset("a-zA-Z0-9_-")))
377-
.map(flatten(1))
378-
.map(join);
379-
380373
/* ---------- */
381374
/* Characters */
382375

test/fixtures/call_expressions.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@
548548
"type": "TermReference",
549549
"id": {
550550
"type": "Identifier",
551-
"name": "-msg"
551+
"name": "msg"
552552
}
553553
}
554554
],

test/fixtures/comments.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"type": "Term",
3131
"id": {
3232
"type": "Identifier",
33-
"name": "-term"
33+
"name": "term"
3434
},
3535
"value": {
3636
"type": "Pattern",

test/fixtures/member_expressions.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"type": "TermReference",
1919
"id": {
2020
"type": "Identifier",
21-
"name": "-term"
21+
"name": "term"
2222
}
2323
},
2424
"key": {

test/fixtures/mixed_entries.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"type": "Term",
1414
"id": {
1515
"type": "Identifier",
16-
"name": "-brand-name"
16+
"name": "brand-name"
1717
},
1818
"value": {
1919
"type": "Pattern",

test/fixtures/reference_expressions.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"type": "TermReference",
4141
"id": {
4242
"type": "Identifier",
43-
"name": "-term"
43+
"name": "term"
4444
}
4545
}
4646
}

test/fixtures/select_expressions.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
"type": "TermReference",
9393
"id": {
9494
"type": "Identifier",
95-
"name": "-term"
95+
"name": "term"
9696
}
9797
},
9898
"name": {

test/fixtures/terms.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"type": "Term",
66
"id": {
77
"type": "Identifier",
8-
"name": "-term01"
8+
"name": "term01"
99
},
1010
"value": {
1111
"type": "Pattern",
@@ -40,7 +40,7 @@
4040
"type": "Term",
4141
"id": {
4242
"type": "Identifier",
43-
"name": "-term02"
43+
"name": "term02"
4444
},
4545
"value": {
4646
"type": "Pattern",

test/fixtures/variables.ftl

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
key01 = {$var}
2+
key02 = { $var }
3+
key03 = {
4+
$var
5+
}
6+
key04 = {
7+
$var}
8+
9+
10+
## Errors
11+
12+
# ERROR Missing variable identifier
13+
err01 = {$}
14+
# ERROR Double $$
15+
err02 = {$$var}
16+
# ERROR Invalid first char of the identifier
17+
err03 = {$-var}

test/fixtures/variables.json

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
{
2+
"type": "Resource",
3+
"body": [
4+
{
5+
"type": "Message",
6+
"id": {
7+
"type": "Identifier",
8+
"name": "key01"
9+
},
10+
"value": {
11+
"type": "Pattern",
12+
"elements": [
13+
{
14+
"type": "Placeable",
15+
"expression": {
16+
"type": "VariableReference",
17+
"id": {
18+
"type": "Identifier",
19+
"name": "var"
20+
}
21+
}
22+
}
23+
]
24+
},
25+
"attributes": [],
26+
"comment": null
27+
},
28+
{
29+
"type": "Message",
30+
"id": {
31+
"type": "Identifier",
32+
"name": "key02"
33+
},
34+
"value": {
35+
"type": "Pattern",
36+
"elements": [
37+
{
38+
"type": "Placeable",
39+
"expression": {
40+
"type": "VariableReference",
41+
"id": {
42+
"type": "Identifier",
43+
"name": "var"
44+
}
45+
}
46+
}
47+
]
48+
},
49+
"attributes": [],
50+
"comment": null
51+
},
52+
{
53+
"type": "Message",
54+
"id": {
55+
"type": "Identifier",
56+
"name": "key03"
57+
},
58+
"value": {
59+
"type": "Pattern",
60+
"elements": [
61+
{
62+
"type": "Placeable",
63+
"expression": {
64+
"type": "VariableReference",
65+
"id": {
66+
"type": "Identifier",
67+
"name": "var"
68+
}
69+
}
70+
}
71+
]
72+
},
73+
"attributes": [],
74+
"comment": null
75+
},
76+
{
77+
"type": "Message",
78+
"id": {
79+
"type": "Identifier",
80+
"name": "key04"
81+
},
82+
"value": {
83+
"type": "Pattern",
84+
"elements": [
85+
{
86+
"type": "Placeable",
87+
"expression": {
88+
"type": "VariableReference",
89+
"id": {
90+
"type": "Identifier",
91+
"name": "var"
92+
}
93+
}
94+
}
95+
]
96+
},
97+
"attributes": [],
98+
"comment": null
99+
},
100+
{
101+
"type": "GroupComment",
102+
"content": "Errors"
103+
},
104+
{
105+
"type": "Comment",
106+
"content": "ERROR Missing variable identifier"
107+
},
108+
{
109+
"type": "Junk",
110+
"annotations": [],
111+
"content": "err01 = {$}\n"
112+
},
113+
{
114+
"type": "Comment",
115+
"content": "ERROR Double $$"
116+
},
117+
{
118+
"type": "Junk",
119+
"annotations": [],
120+
"content": "err02 = {$$var}\n"
121+
},
122+
{
123+
"type": "Comment",
124+
"content": "ERROR Invalid first char of the identifier"
125+
},
126+
{
127+
"type": "Junk",
128+
"annotations": [],
129+
"content": "err03 = {$-var}\n"
130+
}
131+
]
132+
}

test/fixtures/variant_keys.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"type": "Term",
66
"id": {
77
"type": "Identifier",
8-
"name": "-simple-identifier"
8+
"name": "simple-identifier"
99
},
1010
"value": {
1111
"type": "VariantList",
@@ -36,7 +36,7 @@
3636
"type": "Term",
3737
"id": {
3838
"type": "Identifier",
39-
"name": "-identifier-surrounded-by-whitespace"
39+
"name": "identifier-surrounded-by-whitespace"
4040
},
4141
"value": {
4242
"type": "VariantList",
@@ -67,7 +67,7 @@
6767
"type": "Term",
6868
"id": {
6969
"type": "Identifier",
70-
"name": "-int-number"
70+
"name": "int-number"
7171
},
7272
"value": {
7373
"type": "VariantList",
@@ -98,7 +98,7 @@
9898
"type": "Term",
9999
"id": {
100100
"type": "Identifier",
101-
"name": "-float-number"
101+
"name": "float-number"
102102
},
103103
"value": {
104104
"type": "VariantList",

0 commit comments

Comments
 (0)