Sisco/bug fixes#31
Merged
Merged
Conversation
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.
PR Description:
sisco/bug-fixesTitle: Fix keyword query matching & block opener trivia handling
Summary
This PR addresses three bugs discovered in the TinyAst system and introduces a new
ISchemaResolvableQueryinterface to enable proper keyword matching in syntax definitions.Bug Fixes
1.⚠️ Breaking behavior fixed
Query.Keyword()matches wrong keywords in syntax definitionsProblem:
Query.Keyword("uniform")was incorrectly matching ANY keyword in the same category, not just"uniform". This happened becauseMatchesGreen()only checkedIsKeyword()and ignored the text predicate during green-tree pattern matching.Root Cause: The previous implementation used
AnyKeywordQuery().Where(...)which filtered correctly during red-tree traversal but failed during green-tree syntax binding because predicates weren't evaluated.Solution: Introduced
SpecificKeywordQuerythat resolves keyword text →NodeKindvia schema before pattern matching, enabling O(1) kind comparison instead of string matching.2. Block opener trivia incorrectly assigned to first child
Problem: Leading trivia (like indentation) after a block opener's newline was being dropped instead of attached to the first child element.
Fix: Updated
GreenLexer.ParseBlock()to properly separate opener's trailing trivia from the first child's leading trivia.New Features
ISchemaResolvableQueryInterfaceA new internal interface for queries that require schema resolution before green-tree matching:
Key points:
SyntaxBinderautomatically callsResolveWithSchema()before pattern matchingSyntaxTree.Select()resolves automatically when a schema is attachedSequenceQuery,AnyOfQuery, etc.) propagate resolution recursivelyImplementation Details
ISchemaResolvableQueryinterface,SelectRegionsFromTreehookSpecificKeywordQueryclass with schema resolutionISchemaResolvableQueryQuery.Keyword()to returnSpecificKeywordQueryTest Coverage
SpecificKeywordQuerybehaviorBreaking Changes
None for public API — The fix changes internal behavior to match documented expectations. Code using
Query.Keyword()will now correctly match only the specified keyword instead of all keywords in the same category.Migration Notes
If you were (incorrectly) relying on
Query.Keyword("x")matching other keywords, update to useQuery.AnyKeywordorQuery.KeywordCategory("CategoryName")instead.