Skip to content

fixes bug 1451450, parse VariantExpressions with a MessageReference inside #62

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 3 commits into from
Apr 11, 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
4 changes: 2 additions & 2 deletions fluent/syntax/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ def __init__(self, id, name, **kwargs):


class VariantExpression(Expression):
def __init__(self, id, key, **kwargs):
def __init__(self, ref, key, **kwargs):
super(VariantExpression, self).__init__(**kwargs)
self.id = id
self.ref = ref
self.key = key


Expand Down
2 changes: 1 addition & 1 deletion fluent/syntax/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ def get_selector_expression(self, ps):
ps.next()
key = self.get_variant_key(ps)
ps.expect_char(']')
return ast.VariantExpression(literal.id, key)
return ast.VariantExpression(literal, key)

if (ch == '('):
ps.next()
Expand Down
2 changes: 1 addition & 1 deletion fluent/syntax/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def serialize_attribute_expression(expr):

def serialize_variant_expression(expr):
return "{}[{}]".format(
serialize_identifier(expr.id),
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you change this to serialize_expression(expr.of)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Follow-up for this landed.

serialize_expression(expr.ref),
serialize_variant_key(expr.key),
)

Expand Down
14 changes: 11 additions & 3 deletions tests/syntax/fixtures_structure/term.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,17 @@
"type": "Placeable",
"expression": {
"type": "VariantExpression",
"id": {
"type": "Identifier",
"name": "-brand-name",
"ref": {
"type": "MessageReference",
"id": {
"type": "Identifier",
"name": "-brand-name",
"span": {
"type": "Span",
"start": 145,
"end": 156
}
},
"span": {
"type": "Span",
"start": 145,
Expand Down