Skip to content
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

Allow '$' character in key names in the grammar #600

Merged
merged 10 commits into from
Mar 15, 2021

Conversation

odelalleau
Copy link
Collaborator

@odelalleau odelalleau commented Mar 13, 2021

This is a first step towards addressing facebookresearch/hydra#1437

Best reviewed by individual commits

Comment on lines +79 to +84

// Interpolation key, may contain any non special character.
// Note that we can allow '$' because the parser does not support interpolations that
// are only part of a key name, i.e., "${foo${bar}}" is not allowed. As a result, it
// is ok to "consume" all '$' characters within the `INTER_KEY` token.
INTER_KEY: ~[\\{}()[\]:. \t'"]+;
Copy link
Owner

Choose a reason for hiding this comment

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

Side question:
Why are we allowing whitespace in interpolation keys?

Copy link
Collaborator Author

@odelalleau odelalleau Mar 15, 2021

Choose a reason for hiding this comment

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

They are not allowed (what we see here is the set of forbidden characters, and " " is in it)

Comment on lines 22 to 28
_config_key = f"({_id}|\\$)+" # foo, $bar, $foo$bar$
_dot_path_res = f"({_id}(\\.{_id})*)?" # foo, foo.bar3, foo_.b4r.b0z
_dot_path_node = f"(\\.)*({_config_key}(\\.{_config_key})*)?" # foo, .foo.$bar
_inter_node = f"\\${{\\s*{_dot_path_node}\\s*}}" # node interpolation
_arg = "[a-zA-Z_0-9/\\-\\+.$%*@]+" # string representing a resolver argument
_args = f"{_arg}(\\s*,\\s*{_arg})*" # list of resolver arguments
_inter_res = f"\\${{\\s*{_dot_path}\\s*:\\s*{_args}?\\s*}}" # resolver interpolation
_inter_res = f"\\${{\\s*{_dot_path_res}\\s*:\\s*{_args}?\\s*}}" # resolver interp.
Copy link
Owner

Choose a reason for hiding this comment

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

This is becoming quiet complex.
Why do we need both _dot_path_res and _dot_path_node?
res stands for resolver? if so, rename it - this is very confusing. (specially how the definition for it is intertwined with the dotpath definition.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, "res" stands for "resolver". I was trying to make sure it would fit in a single line because it gets worse when black starts making these multi-line. I tried to use better names and a more logical definition order in c3403df.

We need both _node_path and _resolver_path (new names in that commit) because we want to allow $ in node names, but not in resolver names.

tests/test_grammar.py Outdated Show resolved Hide resolved
tests/test_grammar.py Outdated Show resolved Hide resolved
tests/test_grammar.py Outdated Show resolved Hide resolved
Copy link
Owner

@omry omry left a comment

Choose a reason for hiding this comment

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

Looking better.
One suggestion inline.

_inter_node = f"\\${{\\s*{_dot_path_node}\\s*}}" # node interpolation
_node_path = f"(\\.)*({_config_key}(\\.{_config_key})*)?" # foo, .foo.$bar
_node_inter = f"\\${{\\s*{_node_path}\\s*}}" # node interpolation ${foo.bar}
_resolver_path = f"({_id}(\\.{_id})*)?" # foo, ns.bar3, ns_1.ns_2.b0z
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
_resolver_path = f"({_id}(\\.{_id})*)?" # foo, ns.bar3, ns_1.ns_2.b0z
_resolver_name = f"({_id}(\\.{_id})*)?" # foo, ns.bar3, ns_1.ns_2.b0z

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done in d70a31f (including the corresponding rename down below)

Copy link
Owner

@omry omry left a comment

Choose a reason for hiding this comment

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

lgtm

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.

2 participants