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

Conversation

Pike
Copy link
Contributor

@Pike Pike commented Apr 10, 2018

This switches the props of VariantExpression from having a
string id to a MessageReference of

https://bugzilla.mozilla.org/show_bug.cgi?id=1451450

…nside

This switches the props of VariantExpression from having a
string `id` to a `MessageReference` `of`
@Pike Pike requested a review from stasm April 10, 2018 11:41
@@ -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.

super(VariantExpression, self).__init__(**kwargs)
self.id = id
self.of = of
Copy link
Contributor

@stasm stasm Apr 10, 2018

Choose a reason for hiding this comment

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

@Pike, @zbraniecki - do you have opinions on what we should call this? It should fit both MessageReference (now) as well as as ExternalArgument (later).

I looked up a few examples: a.b parses as Attribute(value=Name(id="a"), attr="b") in Python and as MemberExpression(object=Identifier(name="a"), property=Identifier(name="b")) in JavaScript.

Copy link
Collaborator

@zbraniecki zbraniecki Apr 10, 2018

Choose a reason for hiding this comment

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

no strong opinion, I prefer both Python and JS naming scheme over of.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest object as it's generic enough to fit a wide range of expressions. Another idea: how about reference, or ref?

  • -term[varname] would parse as VariantExpression(ref=MessageReference(id=Identifier(name="-term")), key=VariantName(name="varname")).

  • $arg[varname] would parse as VariantExpression(ref=ExternalArgument(id=Identifier(name="-term")), key=VariantName(name="varname")).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ref works for me.

@stasm
Copy link
Contributor

stasm commented Apr 11, 2018

@Pike - I think we should also do this for AttributeExpressions, for the same reasons. It also matters for the compare-locales check.

@Pike
Copy link
Contributor Author

Pike commented Apr 11, 2018

@Pike - I think we should also do this for AttributeExpressions, for the same reasons. It also matters for the compare-locales check.

Actually, I think that'd make it harder to do attribute checks. There's a profound semantic difference between {close-me}, {close-me.label} and {close-me.accesskey}, so I don't think we should take one for the other. If they'd be MessageReferences, the check would need to find MessageReference, but not if it's in an AttributeExpression

@stasm
Copy link
Contributor

stasm commented Apr 11, 2018

Sorry, I didn't make it clear. By "the same reasons" I meant the fact that we'll need to support AttributeExpressions on both MessageReferences and ExternalArguments. We'll make that change in the implementation of Dynamic References. This PR is making ground for it and I'd like it to do it symmetrically for both VariantExpressions and AttributeExpressions, please.

For compare-locales it sounds like we should have a separate check for symmetrical AttributeExpressions of Messages (not Terms).

In fact, perhaps we should consider introducing TermReferences in a follow-up to make this easier?

@Pike
Copy link
Contributor Author

Pike commented Apr 11, 2018

I took a look at AttributeExpression, and the impact of adding a MessageReference in there isn't clear to me at all in the light of compare-locales.

I'd rather not block fixing the term variant fix we have in Firefox today by having to do full attribute support.

@stasm
Copy link
Contributor

stasm commented Apr 11, 2018

OK, I see. I'm a bit worried about this fix then. I think it's a sound design for VariantExpression and it should be extended to AttributeExpression but I see how the latter would make some static analysis harder. Perhaps we need a sister method to BaseNode.traverse then, with a slightly different mechanics, e.g. return True if the traversal should continue deeper.

@Pike
Copy link
Contributor Author

Pike commented Apr 11, 2018

I really liked https://github.com/estools/esquery when doing my js ast jazz for the react editors, I've contemplated doing something similar. I also found traverse to be pretty excessive, i.e., it goes to each number in spans, which I don't need in compare-locales checks at all ;-)

@stasm
Copy link
Contributor

stasm commented Apr 11, 2018

Let's decide what the name of the of field should be and let's land this to unblock Firefox.

Copy link
Contributor

@stasm stasm left a comment

Choose a reason for hiding this comment

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

r=me with the s/of/ref change.

@Pike Pike merged commit caa1efa into projectfluent:master Apr 11, 2018
@Pike Pike deleted the variant-expression branch April 11, 2018 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants