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.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Search Bar/Query/Default Syntax] Parser support for "recognizedFields" options #7960
[Search Bar/Query/Default Syntax] Parser support for "recognizedFields" options #7960
Changes from 7 commits
4778c74
c5a8707
99c447c
e10c801
0faad32
bcdfdb7
707a9d0
76b1010
5e92233
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the ampersand doing here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pugnascotia
Unfortunately, PegJS documentation is no longer available directly, but it can be found here: http://web.archive.org/web/20240102234657/https://pegjs.org/documentation. Take a look under "Parsing Expression Types"
In other words, the
&{ return !hasRecognizedFields || recognizedFields.includes(id); }
is a predicate check that determines whether the rule succeeds or fails. This check ensures that ifhasRecognizedFields
is truthy, then there is a restriction that the identifier must be included in therecognizedFields
array to be treated as a field name. If the predicate passes, then the identifier is parsed as a field name. If the predicate does not pass, then thefieldName
match is failed and the parser falls back to using theidentifier
rule.By the way, I used Microsoft Copilot to explain this to me and help me with updating the parsing rules. If it wasn't for that, I am sure I would not have been able to figure it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked the docs as they appear in source control, to double-check:
https://github.com/pegjs/pegjs/blob/master/docs/grammar/parsing-expression-types.md#--predicate-
So this looks good.