Skip to content

Allow whitespace before CallArguments (fixes #421) #422

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 1 commit into from
Aug 9, 2019
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
8 changes: 6 additions & 2 deletions fluent-syntax/src/parser.js
Original file line number Diff line number Diff line change
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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alternatively, you could store the ptr, skipBlank and then only take currentChar === "." if stored_ptr == ptr.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's like re-implementing peek, that doesn't smell right. If I'd want to change this, I'd look for ways to structure the code so that I could just eat the whitespace, because there's no grammar structure that doesn't allow it.

But then I didn't want to invest my brain in that, too.


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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
}

key01 = { -term }
key02 = { -term() }
key02 = { -term () }
key03 = { -term(arg: 1) }
key04 = { -term("positional", narg1: 1, narg2: 2) }