Skip to content

Commit 40a5872

Browse files
committed
Allow whitespace before CallArguments (fixes #421)
This is picking up the tests for projectfluent/fluent#281, and adjusts the parser to pass those tests.
1 parent 4312437 commit 40a5872

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

fluent-syntax/src/parser.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,9 @@ class FluentParser {
676676
}
677677

678678
let args;
679-
if (ps.currentChar === "(") {
679+
ps.peekBlank()
680+
if (ps.currentPeek === "(") {
681+
ps.skipToPeek()
680682
args = this.getCallArguments(ps);
681683
}
682684

@@ -685,13 +687,15 @@ class FluentParser {
685687

686688
if (ps.isIdentifierStart()) {
687689
const id = this.getIdentifier(ps);
690+
ps.peekBlank();
688691

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

698+
ps.skipToPeek();
695699
let args = this.getCallArguments(ps);
696700
return new AST.FunctionReference(id, args);
697701
}

fluent-syntax/test/fixtures_reference/call_expressions.ftl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ duplicate-named-args = {FUN(x: 1, x: "X")}
2929
3030
## Whitespace around arguments
3131

32-
sparse-inline-call = {FUN( "a" , msg, x: 1 )}
32+
sparse-inline-call = {FUN ( "a" , msg, x: 1 )}
3333
empty-inline-call = {FUN( )}
3434
multiline-call = {FUN(
3535
"a",
3636
msg,
3737
x: 1
3838
)}
39-
sparse-multiline-call = {FUN(
39+
sparse-multiline-call = {FUN
40+
(
4041
4142
"a" ,
4243
msg

fluent-syntax/test/fixtures_reference/term_parameters.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
}
44
55
key01 = { -term }
6-
key02 = { -term() }
6+
key02 = { -term () }
77
key03 = { -term(arg: 1) }
88
key04 = { -term("positional", narg1: 1, narg2: 2) }

0 commit comments

Comments
 (0)