Support block comments in selector filter syntax (#5023)

The filter_elements selector grammar had no way to comment out part of a
query, so users had to delete and retype text to temporarily toggle a
facet. Add a /* ... */ block comment terminal that is ignored by the
lexer, and tolerate a trailing "+" so that commenting out the final
operand (e.g. "IfcWall + /* IfcSlab */") parses cleanly. Comments may
span multiple lines; a /* sequence inside a quoted string is not treated
as a comment. Only the filter grammar is affected, not get_element or
format which use "/" for regex and division.

Adds a regression test and documents the syntax.

Generated with the assistance of an AI coding tool.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit 5c11946470)
This commit is contained in:
Petru Conduraru
2026-07-12 07:45:21 +03:00
committed by Dion Moult
parent d39b1c56f8
commit 007573cea5
3 changed files with 24 additions and 1 deletions
@@ -41,7 +41,7 @@ import ifcopenshell.util.unit
filter_elements_grammar = lark.Lark(
"""start: filter_group
filter_group: facet_list ("+" facet_list)*
filter_group: facet_list ("+" facet_list)* "+"?
facet_list: facet ("," facet)*
facet: instance | entity | attribute | type | material | query | classification | location | property | group | parent
@@ -109,8 +109,10 @@ filter_elements_grammar = lark.Lark(
CR : /\\r/
LF : /\\n/
NEWLINE: (CR? LF)+
COMMENT: "/*" /.*?/s "*/"
%ignore WS // Disregard spaces in text
%ignore COMMENT // Allow /* ... */ block comments to toggle parts of a query
"""
)