Skip to content

search: refactor parser to simplify regex and literal handling

Administrator requested to merge rvt/parser-cleanup-2 into main

Created by: rvantonder

Closes https://github.com/sourcegraph/sourcegraph/issues/13434. This is a pretty hefty refactor to get rid of a kind of 'forked' handling of parsing. Before, it basically did:

              /----- parseLeavesLiteral (literal search)------\                   /--parsePatternLiteral-\
input  -----                                                   ----shared stuff---                        -- ....
              \---------- parseLeavesRegexp (regexp search)---/                   \--parsePatternRegexp--/

these forked/analog functions shared things, but also different and separated by the fact that I implemented literal search support after regex. They share enough logic that they should be merged (read: PR has more deletions than additions :P). After this PR, the structure is:

input -- parseLeaves (arg has literal or regex context) --- stuff --- parsePattern (arg has context) ---...

This will make it easier to translate some of the logic to frontend parser, see #14016.

With this change, I also decide to drop support for dangling closing parentheses. Mainly because I don't think handling this edge case is worth the amount of complexity it adds to the code. There's no harm in dropping support if we flag it, and provide the alternative (content:"thing with )")

Merge request reports

Loading