Skip to content

Syntax 0.8, part 6: Parameterized term attributes #313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fluent-syntax/src/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function getErrorMessage(code, args) {
case "E0007":
return "Keyword cannot end with a whitespace";
case "E0008":
return "The callee has to be a simple, upper-case identifier";
return "The callee has to be an upper-case identifier or a term";
case "E0009":
return "The key has to be a simple identifier";
case "E0010":
Expand Down
28 changes: 20 additions & 8 deletions fluent-syntax/src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -678,11 +678,18 @@ export default class FluentParser {

const variants = this.getVariants(ps, {allowVariantList: false});
return new AST.SelectExpression(selector, variants);
} else if (selector.type === "AttributeExpression"
}

if (selector.type === "AttributeExpression"
&& selector.ref.type === "TermReference") {
throw new ParseError("E0019");
}

if (selector.type === "CallExpression"
&& selector.callee.type === "AttributeExpression") {
throw new ParseError("E0019");
}

return selector;
}

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

const selector = this.getLiteral(ps);
let selector = this.getLiteral(ps);
switch (selector.type) {
case "StringLiteral":
case "NumberLiteral":
case "VariableReference":
return selector;
}

if (ps.currentChar === ".") {
ps.next();
const attr = this.getIdentifier(ps);
return new AST.AttributeExpression(selector, attr);
}

if (ps.currentChar === "[") {
ps.next();

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

if (ps.currentChar === ".") {
ps.next();
const attr = this.getIdentifier(ps);
selector = new AST.AttributeExpression(selector, attr);
}

if (ps.currentChar === "(") {
ps.next();

Expand All @@ -733,6 +740,11 @@ export default class FluentParser {
}
}

if (selector.type === "AttributeExpression"
&& selector.ref.type === "MessageReference") {
throw new ParseError("E0008");
}

const args = this.getCallArgs(ps);
ps.expectChar(")");

Expand Down
13 changes: 0 additions & 13 deletions fluent-syntax/test/fixtures_reference/call_expressions.ftl
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
## Callees

function-callee = {FUNCTION()}
term-callee = {-term()}

# ERROR Equivalent to a MessageReference callee.
mixed-case-callee = {Function()}

# ERROR MessageReference is not a valid callee.
message-callee = {message()}
# ERROR VariableReference is not a valid callee.
variable-callee = {$variable()}

## Arguments

positional-args = {FUN(1, "a", msg)}
Expand Down
89 changes: 0 additions & 89 deletions fluent-syntax/test/fixtures_reference/call_expressions.json
Original file line number Diff line number Diff line change
@@ -1,95 +1,6 @@
{
"type": "Resource",
"body": [
{
"type": "GroupComment",
"content": "Callees"
},
{
"type": "Message",
"id": {
"type": "Identifier",
"name": "function-callee"
},
"value": {
"type": "Pattern",
"elements": [
{
"type": "Placeable",
"expression": {
"type": "CallExpression",
"callee": {
"type": "FunctionReference",
"id": {
"type": "Identifier",
"name": "FUNCTION"
}
},
"positional": [],
"named": []
}
}
]
},
"attributes": [],
"comment": null
},
{
"type": "Message",
"id": {
"type": "Identifier",
"name": "term-callee"
},
"value": {
"type": "Pattern",
"elements": [
{
"type": "Placeable",
"expression": {
"type": "CallExpression",
"callee": {
"type": "TermReference",
"id": {
"type": "Identifier",
"name": "term"
}
},
"positional": [],
"named": []
}
}
]
},
"attributes": [],
"comment": null
},
{
"type": "Comment",
"content": "ERROR Equivalent to a MessageReference callee."
},
{
"type": "Junk",
"annotations": [],
"content": "mixed-case-callee = {Function()}\n\n"
},
{
"type": "Comment",
"content": "ERROR MessageReference is not a valid callee."
},
{
"type": "Junk",
"annotations": [],
"content": "message-callee = {message()}\n"
},
{
"type": "Comment",
"content": "ERROR VariableReference is not a valid callee."
},
{
"type": "Junk",
"annotations": [],
"content": "variable-callee = {$variable()}\n\n"
},
{
"type": "GroupComment",
"content": "Arguments"
Expand Down
46 changes: 46 additions & 0 deletions fluent-syntax/test/fixtures_reference/callee_expressions.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
## Callees in placeables.

function-callee-placeable = {FUNCTION()}
term-callee-placeable = {-term()}

# ERROR Messages cannot be parameterized.
message-callee-placeable = {message()}
# ERROR Equivalent to a MessageReference callee.
mixed-case-callee-placeable = {Function()}
# ERROR Message attributes cannot be parameterized.
message-attr-callee-placeable = {message.attr()}
# ERROR Term attributes may not be used in Placeables.
term-attr-callee-placeable = {-term.attr()}
# ERROR Variables cannot be parameterized.
variable-callee-placeable = {$variable()}


## Callees in selectors.

function-callee-selector = {FUNCTION() ->
*[key] Value
}
term-attr-callee-selector = {-term.attr() ->
*[key] Value
}

# ERROR Messages cannot be parameterized.
message-callee-selector = {message() ->
*[key] Value
}
# ERROR Equivalent to a MessageReference callee.
mixed-case-callee-selector = {Function() ->
*[key] Value
}
# ERROR Message attributes cannot be parameterized.
message-attr-callee-selector = {message.attr() ->
*[key] Value
}
# ERROR Term values may not be used as selectors.
term-callee-selector = {-term() ->
*[key] Value
}
# ERROR Variables cannot be parameterized.
variable-callee-selector = {$variable() ->
*[key] Value
}
Loading