Skip to content

Allow whitespace before CallArguments (fixes #124) #125

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 2 commits into from
Sep 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/fluent/syntax/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,17 +564,21 @@ def get_inline_expression(self, ps):
ps.next()
attribute = self.get_identifier(ps)
arguments = None
if ps.current_char == '(':
ps.peek_blank()
if ps.current_peek == '(':
ps.skip_to_peek()
arguments = self.get_call_arguments(ps)
return ast.TermReference(id, attribute, arguments)

if ps.is_identifier_start():
id = self.get_identifier(ps)
ps.peek_blank()

if ps.current_char == '(':
if ps.current_peek == '(':
# It's a Function. Ensure it's all upper-case.
if not re.match('^[A-Z][A-Z0-9_-]*$', id.name):
raise ParseError('E0008')
ps.skip_to_peek()
args = self.get_call_arguments(ps)
return ast.FunctionReference(id, args)

Expand Down
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
7 changes: 6 additions & 1 deletion fluent.syntax/tests/syntax/fixtures_reference/comments.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ foo = Foo
-term = Term

# Another standalone
#
#
# with indent
## Group Comment
### Resource Comment

# Errors
#error
##error
###error
19 changes: 19 additions & 0 deletions fluent.syntax/tests/syntax/fixtures_reference/comments.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,25 @@
{
"type": "ResourceComment",
"content": "Resource Comment"
},
{
"type": "Comment",
"content": "Errors"
},
{
"type": "Junk",
"annotations": [],
"content": "#error\n"
},
{
"type": "Junk",
"annotations": [],
"content": "##error\n"
},
{
"type": "Junk",
"annotations": [],
"content": "###error\n"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ backslash-in-string = {"\\"}
mismatched-quote = {"\\""}
# ERROR Unknown escape
unknown-escape = {"\x"}
# ERROR Multiline literal
invalid-multiline-literal = {"
"}

## Unicode escapes
string-unicode-4digits = {"\u0041"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,16 @@
{
"type": "Junk",
"annotations": [],
"content": "unknown-escape = {\"\\x\"}\n\n"
"content": "unknown-escape = {\"\\x\"}\n"
},
{
"type": "Comment",
"content": "ERROR Multiline literal"
},
{
"type": "Junk",
"annotations": [],
"content": "invalid-multiline-literal = {\"\n \"}\n\n"
},
{
"type": "GroupComment",
Expand Down
6 changes: 6 additions & 0 deletions fluent.syntax/tests/syntax/fixtures_reference/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ key04 =
key05 =
.attr1 = Attribute 1

no-whitespace=Value
.attr1=Attribute 1

extra-whitespace = Value
.attr1 = Attribute 1

key06 = {""}

# JUNK Missing value
Expand Down
70 changes: 70 additions & 0 deletions fluent.syntax/tests/syntax/fixtures_reference/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,76 @@
"content": " < whitespace >"
}
},
{
"type": "Message",
"id": {
"type": "Identifier",
"name": "no-whitespace"
},
"value": {
"type": "Pattern",
"elements": [
{
"type": "TextElement",
"value": "Value"
}
]
},
"attributes": [
{
"type": "Attribute",
"id": {
"type": "Identifier",
"name": "attr1"
},
"value": {
"type": "Pattern",
"elements": [
{
"type": "TextElement",
"value": "Attribute 1"
}
]
}
}
],
"comment": null
},
{
"type": "Message",
"id": {
"type": "Identifier",
"name": "extra-whitespace"
},
"value": {
"type": "Pattern",
"elements": [
{
"type": "TextElement",
"value": "Value"
}
]
},
"attributes": [
{
"type": "Attribute",
"id": {
"type": "Identifier",
"name": "attr1"
},
"value": {
"type": "Pattern",
"elements": [
{
"type": "TextElement",
"value": "Attribute 1"
}
]
}
}
],
"comment": null
},
{
"type": "Message",
"id": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ invalid-selector-term-variant =
}

# ERROR Nested expressions are not valid selectors
invalid-selector-select-expression =
invalid-selector-nested-expression =
{ { 3 } ->
*[key] default
}

# ERROR Select expressions are not valid selectors
invalid-selector-nested-expression =
invalid-selector-select-expression =
{ { $sel ->
*[key] value
} ->
Expand All @@ -40,6 +40,11 @@ empty-variant =
*[key] {""}
}

reduced-whitespace =
{FOO()->
*[key] {""}
}

nested-select =
{ $sel ->
*[one] { $sel ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
{
"type": "Junk",
"annotations": [],
"content": "invalid-selector-select-expression =\n { { 3 } ->\n *[key] default\n }\n\n"
"content": "invalid-selector-nested-expression =\n { { 3 } ->\n *[key] default\n }\n\n"
},
{
"type": "Comment",
Expand All @@ -161,7 +161,7 @@
{
"type": "Junk",
"annotations": [],
"content": "invalid-selector-nested-expression =\n { { $sel ->\n *[key] value\n } ->\n *[key] default\n }\n\n"
"content": "invalid-selector-select-expression =\n { { $sel ->\n *[key] value\n } ->\n *[key] default\n }\n\n"
},
{
"type": "Message",
Expand Down Expand Up @@ -212,6 +212,60 @@
"attributes": [],
"comment": null
},
{
"type": "Message",
"id": {
"type": "Identifier",
"name": "reduced-whitespace"
},
"value": {
"type": "Pattern",
"elements": [
{
"type": "Placeable",
"expression": {
"type": "SelectExpression",
"selector": {
"type": "FunctionReference",
"id": {
"type": "Identifier",
"name": "FOO"
},
"arguments": {
"type": "CallArguments",
"positional": [],
"named": []
}
},
"variants": [
{
"type": "Variant",
"key": {
"type": "Identifier",
"name": "key"
},
"value": {
"type": "Pattern",
"elements": [
{
"type": "Placeable",
"expression": {
"value": "",
"type": "StringLiteral"
}
}
]
},
"default": true
}
]
}
}
]
},
"attributes": [],
"comment": null
},
{
"type": "Message",
"id": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ select-1tbs-indent = {
select-allman-inline =
{ $selector ->
*[key] Value
[other] Other
}

select-allman-newline =
Expand Down
17 changes: 17 additions & 0 deletions fluent.syntax/tests/syntax/fixtures_reference/select_indent.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,23 @@
]
},
"default": true
},
{
"type": "Variant",
"key": {
"type": "Identifier",
"name": "other"
},
"value": {
"type": "Pattern",
"elements": [
{
"type": "TextElement",
"value": "Other"
}
]
},
"default": false
}
]
}
Expand Down
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) }
6 changes: 6 additions & 0 deletions fluent.syntax/tests/syntax/fixtures_reference/terms.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@

# JUNK Missing =
-term07

-term08=Value
.attr=Attribute

-term09 = Value
.attr = Attribute
Loading