Skip to content

Commit 2cad174

Browse files
authored
Merge pull request #313 from stasm/zeroeight-part6-macro-attrs
Syntax 0.8, part 6: Parameterized term attributes
2 parents 4374b3b + cb22f54 commit 2cad174

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2164
-815
lines changed

fluent-syntax/src/errors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function getErrorMessage(code, args) {
3333
case "E0007":
3434
return "Keyword cannot end with a whitespace";
3535
case "E0008":
36-
return "The callee has to be a simple, upper-case identifier";
36+
return "The callee has to be an upper-case identifier or a term";
3737
case "E0009":
3838
return "The key has to be a simple identifier";
3939
case "E0010":

fluent-syntax/src/parser.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -678,11 +678,18 @@ export default class FluentParser {
678678

679679
const variants = this.getVariants(ps, {allowVariantList: false});
680680
return new AST.SelectExpression(selector, variants);
681-
} else if (selector.type === "AttributeExpression"
681+
}
682+
683+
if (selector.type === "AttributeExpression"
682684
&& selector.ref.type === "TermReference") {
683685
throw new ParseError("E0019");
684686
}
685687

688+
if (selector.type === "CallExpression"
689+
&& selector.callee.type === "AttributeExpression") {
690+
throw new ParseError("E0019");
691+
}
692+
686693
return selector;
687694
}
688695

@@ -691,20 +698,14 @@ export default class FluentParser {
691698
return this.getPlaceable(ps);
692699
}
693700

694-
const selector = this.getLiteral(ps);
701+
let selector = this.getLiteral(ps);
695702
switch (selector.type) {
696703
case "StringLiteral":
697704
case "NumberLiteral":
698705
case "VariableReference":
699706
return selector;
700707
}
701708

702-
if (ps.currentChar === ".") {
703-
ps.next();
704-
const attr = this.getIdentifier(ps);
705-
return new AST.AttributeExpression(selector, attr);
706-
}
707-
708709
if (ps.currentChar === "[") {
709710
ps.next();
710711

@@ -717,6 +718,12 @@ export default class FluentParser {
717718
return new AST.VariantExpression(selector, key);
718719
}
719720

721+
if (ps.currentChar === ".") {
722+
ps.next();
723+
const attr = this.getIdentifier(ps);
724+
selector = new AST.AttributeExpression(selector, attr);
725+
}
726+
720727
if (ps.currentChar === "(") {
721728
ps.next();
722729

@@ -733,6 +740,11 @@ export default class FluentParser {
733740
}
734741
}
735742

743+
if (selector.type === "AttributeExpression"
744+
&& selector.ref.type === "MessageReference") {
745+
throw new ParseError("E0008");
746+
}
747+
736748
const args = this.getCallArgs(ps);
737749
ps.expectChar(")");
738750

fluent-syntax/test/fixtures_reference/call_expressions.ftl

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
## Callees
2-
3-
function-callee = {FUNCTION()}
4-
term-callee = {-term()}
5-
6-
# ERROR Equivalent to a MessageReference callee.
7-
mixed-case-callee = {Function()}
8-
9-
# ERROR MessageReference is not a valid callee.
10-
message-callee = {message()}
11-
# ERROR VariableReference is not a valid callee.
12-
variable-callee = {$variable()}
13-
141
## Arguments
152

163
positional-args = {FUN(1, "a", msg)}

fluent-syntax/test/fixtures_reference/call_expressions.json

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,6 @@
11
{
22
"type": "Resource",
33
"body": [
4-
{
5-
"type": "GroupComment",
6-
"content": "Callees"
7-
},
8-
{
9-
"type": "Message",
10-
"id": {
11-
"type": "Identifier",
12-
"name": "function-callee"
13-
},
14-
"value": {
15-
"type": "Pattern",
16-
"elements": [
17-
{
18-
"type": "Placeable",
19-
"expression": {
20-
"type": "CallExpression",
21-
"callee": {
22-
"type": "FunctionReference",
23-
"id": {
24-
"type": "Identifier",
25-
"name": "FUNCTION"
26-
}
27-
},
28-
"positional": [],
29-
"named": []
30-
}
31-
}
32-
]
33-
},
34-
"attributes": [],
35-
"comment": null
36-
},
37-
{
38-
"type": "Message",
39-
"id": {
40-
"type": "Identifier",
41-
"name": "term-callee"
42-
},
43-
"value": {
44-
"type": "Pattern",
45-
"elements": [
46-
{
47-
"type": "Placeable",
48-
"expression": {
49-
"type": "CallExpression",
50-
"callee": {
51-
"type": "TermReference",
52-
"id": {
53-
"type": "Identifier",
54-
"name": "term"
55-
}
56-
},
57-
"positional": [],
58-
"named": []
59-
}
60-
}
61-
]
62-
},
63-
"attributes": [],
64-
"comment": null
65-
},
66-
{
67-
"type": "Comment",
68-
"content": "ERROR Equivalent to a MessageReference callee."
69-
},
70-
{
71-
"type": "Junk",
72-
"annotations": [],
73-
"content": "mixed-case-callee = {Function()}\n\n"
74-
},
75-
{
76-
"type": "Comment",
77-
"content": "ERROR MessageReference is not a valid callee."
78-
},
79-
{
80-
"type": "Junk",
81-
"annotations": [],
82-
"content": "message-callee = {message()}\n"
83-
},
84-
{
85-
"type": "Comment",
86-
"content": "ERROR VariableReference is not a valid callee."
87-
},
88-
{
89-
"type": "Junk",
90-
"annotations": [],
91-
"content": "variable-callee = {$variable()}\n\n"
92-
},
934
{
945
"type": "GroupComment",
956
"content": "Arguments"
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
## Callees in placeables.
2+
3+
function-callee-placeable = {FUNCTION()}
4+
term-callee-placeable = {-term()}
5+
6+
# ERROR Messages cannot be parameterized.
7+
message-callee-placeable = {message()}
8+
# ERROR Equivalent to a MessageReference callee.
9+
mixed-case-callee-placeable = {Function()}
10+
# ERROR Message attributes cannot be parameterized.
11+
message-attr-callee-placeable = {message.attr()}
12+
# ERROR Term attributes may not be used in Placeables.
13+
term-attr-callee-placeable = {-term.attr()}
14+
# ERROR Variables cannot be parameterized.
15+
variable-callee-placeable = {$variable()}
16+
17+
18+
## Callees in selectors.
19+
20+
function-callee-selector = {FUNCTION() ->
21+
*[key] Value
22+
}
23+
term-attr-callee-selector = {-term.attr() ->
24+
*[key] Value
25+
}
26+
27+
# ERROR Messages cannot be parameterized.
28+
message-callee-selector = {message() ->
29+
*[key] Value
30+
}
31+
# ERROR Equivalent to a MessageReference callee.
32+
mixed-case-callee-selector = {Function() ->
33+
*[key] Value
34+
}
35+
# ERROR Message attributes cannot be parameterized.
36+
message-attr-callee-selector = {message.attr() ->
37+
*[key] Value
38+
}
39+
# ERROR Term values may not be used as selectors.
40+
term-callee-selector = {-term() ->
41+
*[key] Value
42+
}
43+
# ERROR Variables cannot be parameterized.
44+
variable-callee-selector = {$variable() ->
45+
*[key] Value
46+
}

0 commit comments

Comments
 (0)