Skip to content

search: Include ranges in query parse nodes and fix parenthesis

Warren Gifford requested to merge fkling/fix-query-parser into main

Created by: fkling

In preparation for being able to highlight AND and OR operators (see #38336), this commit adds character ranges to search query parse nodes (represented via the parse field). Groups (e.g. (a or b)) do not have a special representation in the parse tree, but for highlighting it would be nicer if the parenthesis were including. That's why operator nodes also have an optional groupRange property. There might be a better way to represent this, please let me know!

While working on this I also discovered some bugs in the parser and the scanner which I tried to fix to the best of my abilities. Please let me know if there are better ways to fix them:

  • Parsing of grouping parenthesis only works if the group is the right operand (e.g. a and (b or c)). (a or b) and c however is parsed the same as a or (b and c). I tried to fix this inside parseLeaves but eventually introduced a new helper function for parsing groups.
  • If there are two consecutive closing group parenthesis, e.g. (a and (b or c)), the scanner adds an empty pattern token between the two (which in turn causes the parser to fail). This seems like a mistake. Only emitting a pattern token when it has a value seems to fix the issue, but I don't know if that's the correct fix.

Test plan

Unit tests and manual testing.

App preview:

Check out the client app preview documentation to learn more.

Merge request reports

Loading