Skip to content

Commit

Permalink
Allow whitespace before CallArguments (fixes projectfluent#421)
Browse files Browse the repository at this point in the history
This is picking up the tests for projectfluent/fluent#281,
and adjusts the parser to pass those tests.
  • Loading branch information
Pike committed Aug 9, 2019
1 parent 4312437 commit 77c1406
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
8 changes: 6 additions & 2 deletions fluent-syntax/src/parser.js
Expand Up @@ -676,7 +676,9 @@ class FluentParser {
}

let args;
if (ps.currentChar === "(") {
ps.peekBlank();
if (ps.currentPeek === "(") {
ps.skipToPeek();
args = this.getCallArguments(ps);
}

Expand All @@ -685,13 +687,15 @@ class FluentParser {

if (ps.isIdentifierStart()) {
const id = this.getIdentifier(ps);
ps.peekBlank();

if (ps.currentChar === "(") {
if (ps.currentPeek === "(") {
// It's a Function. Ensure it's all upper-case.
if (!/^[A-Z][A-Z0-9_-]*$/.test(id.name)) {
throw new ParseError("E0008");
}

ps.skipToPeek();
let args = this.getCallArguments(ps);
return new AST.FunctionReference(id, args);
}
Expand Down
5 changes: 3 additions & 2 deletions fluent-syntax/test/fixtures_reference/call_expressions.ftl
Expand Up @@ -29,14 +29,15 @@ duplicate-named-args = {FUN(x: 1, x: "X")}
## Whitespace around arguments

sparse-inline-call = {FUN( "a" , msg, x: 1 )}
sparse-inline-call = {FUN ( "a" , msg, x: 1 )}
empty-inline-call = {FUN( )}
multiline-call = {FUN(
"a",
msg,
x: 1
)}
sparse-multiline-call = {FUN(
sparse-multiline-call = {FUN
(
"a" ,
msg
Expand Down
2 changes: 1 addition & 1 deletion fluent-syntax/test/fixtures_reference/term_parameters.ftl
Expand Up @@ -3,6 +3,6 @@
}
key01 = { -term }
key02 = { -term() }
key02 = { -term () }
key03 = { -term(arg: 1) }
key04 = { -term("positional", narg1: 1, narg2: 2) }

0 comments on commit 77c1406

Please sign in to comment.