From 2298201e50259b798bc7134e550321c20e1b3ca2 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Sat, 26 Aug 2023 16:42:18 +1000 Subject: [PATCH] Selector element key queries now allow for regex matching, and single regex matches return that only item, not a list with one item in it. --- .../ifcopenshell/util/selector.py | 130 ++++++++++++------ 1 file changed, 86 insertions(+), 44 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/selector.py b/src/ifcopenshell-python/ifcopenshell/util/selector.py index 0acd0aa44e..095a9df50e 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/selector.py +++ b/src/ifcopenshell-python/ifcopenshell/util/selector.py @@ -52,8 +52,8 @@ filter_elements_grammar = lark.Lark( value: special | quoted_string | regex_string | unquoted_string unquoted_string: /[^.=\\s]+/ - quoted_string: ESCAPED_STRING regex_string: "/" /[^\\/]+/ "/" + quoted_string: ESCAPED_STRING special: null | true | false @@ -94,19 +94,18 @@ filter_elements_grammar = lark.Lark( ) get_element_grammar = lark.Lark( - """start: WORD | ESCAPED_STRING | keys_regex | keys_quoted | keys_simple - keys_regex: "r" ESCAPED_STRING ("." ESCAPED_STRING)* - keys_quoted: ESCAPED_STRING ("." ESCAPED_STRING)* - keys_simple: /[^\\W][^.=<>!%*\\]]*/ ("." /[^\\W][^.=<>!%*\\]]*/)* + """start: keys + + keys: key ("." key)* + key: quoted_string | regex_string | unquoted_string + unquoted_string: /[^.=\\/\\s]+/ + regex_string: "/" /[^\\/]+/ "/" + quoted_string: ESCAPED_STRING // Embed common.lark for packaging _STRING_INNER: /.*?/ _STRING_ESC_INNER: _STRING_INNER /(?