diff --git a/benchmark/benchmark.py b/benchmark/benchmark.py index 1c77ad281..989647080 100644 --- a/benchmark/benchmark.py +++ b/benchmark/benchmark.py @@ -134,6 +134,7 @@ def iterate(seq: Any) -> None: ("${a:b,c,d}", ValueKind.INTERPOLATION), ("${${b}}", ValueKind.INTERPOLATION), ("${a:${b}}", ValueKind.INTERPOLATION), + ("${foooooooooooooooooooo}_${bar}", ValueKind.INTERPOLATION), ], ) def test_get_value_kind( diff --git a/omegaconf/grammar_parser.py b/omegaconf/grammar_parser.py index 181e702c9..9d660618f 100644 --- a/omegaconf/grammar_parser.py +++ b/omegaconf/grammar_parser.py @@ -18,10 +18,10 @@ # Build regex pattern to efficiently identify typical interpolations. # See test `test_match_simple_interpolation_pattern` for examples. -_id = "[a-zA-Z_]\\w*" # foo, foo_bar, abc123 -_config_key = f"({_id}|\\$)+" # foo, $bar, $foo$bar$ +_config_key = r"[$\w]+" # foo, $0, $bar, $foo_$bar123$ _node_path = f"(\\.)*({_config_key}(\\.{_config_key})*)?" # foo, .foo.$bar _node_inter = f"\\${{\\s*{_node_path}\\s*}}" # node interpolation ${foo.bar} +_id = "[a-zA-Z_]\\w*" # foo, foo_bar, abc123 _resolver_name = f"({_id}(\\.{_id})*)?" # foo, ns.bar3, ns_1.ns_2.b0z _arg = "[a-zA-Z_0-9/\\-\\+.$%*@]+" # string representing a resolver argument _args = f"{_arg}(\\s*,\\s*{_arg})*" # list of resolver arguments diff --git a/tests/test_grammar.py b/tests/test_grammar.py index 963b9b11d..b46e5df18 100644 --- a/tests/test_grammar.py +++ b/tests/test_grammar.py @@ -531,6 +531,8 @@ def visit() -> Any: "\\${foo}", "${foo.bar:boz}", "${$foo.bar$.x$y}", + "${$0.1.2$}", + "${0foo}", # relative interpolations "${.}", "${..}", @@ -548,7 +550,6 @@ def test_match_simple_interpolation_pattern(expression: str) -> None: "expression", [ "${foo", - "${0foo}", "${0foo:bar}", "${foo.${bar}}", "${foo:${bar}}",