fix/query: preserve fields in parenthesized atoms#1078
Draft
keegancsmith wants to merge 1 commit into
Draft
Conversation
Users reasonably expect wrapping a field query in parentheses to preserve its semantics, but the parser's regex/grouping ambiguity caused no-space forms like (sym:foo) to be treated as plain content text. Recognize field-looking parenthesized atoms as grouping so generated and hand-written field queries behave consistently while leaving bare regex grouping such as (foo) and (foo|bar) alone. Amp-Thread-ID: https://ampcode.com/threads/T-019ef884-75bf-736d-b3b7-e19a7855d882 Co-authored-by: Amp <amp@ampcode.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes a parser ambiguity where no-space parenthesized field atoms like
(sym:foo)were treated as plain content text instead of as grouped field queries. The tokenizer now recognizes parenthesized atoms that begin with query field syntax as grouping, so field semantics are preserved for cases like(sym:foo),(file:README), and negated forms like-(file:test). Bare regex-style parenthesized text such as(foo)and(foo)(bar)remains on the existing path to avoid broad compatibility churn.\n\nThe query syntax and design docs now call out that parenthesized field expressions preserve their field semantics.\n\nFixes #1074.\n\n## Test Plan\n\ngo test ./querypasses.\n\ngo test ./... -shortwas run; it failed ingithub.com/sourcegraph/zoekt/gitindexatTestCatfileReader_ExcludedwithNext large.bin: EOF. Rerunning justgo test ./gitindex -short -run TestCatfileReader_Excluded -count=1 -vreproduced the same failure, which appears unrelated to this parser-only change.