Yeast/Unified: Extract comments#21981
Open
asgerf wants to merge 5 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR preserves tree-sitter extra nodes (notably comments) across Yeast desugaring by extracting them from the original parse tree and emitting them as TriviaTokens, enabling inline expectation tests and other comment-based workflows to function after rewriting.
Changes:
- Extend the tree-sitter extractor generator to optionally generate a
TriviaTokenclass and associated*_trivia_tokeninfotable when desugaring is enabled. - Update extraction to traverse the original tree-sitter parse tree for
extranodes after desugaring and emit them asTriviaTokens with locations and source text. - Add a Unified QL API surface for comments plus a new library-test that asserts comment extraction works for Swift input.
Show a summary per file
| File | Description |
|---|---|
| unified/ql/test/library-tests/comments/comments.swift | New Swift input containing line and block comments for coverage. |
| unified/ql/test/library-tests/comments/comments.ql | New library test query predicate exposing extracted comment text. |
| unified/ql/test/library-tests/comments/comments.expected | Expected results for comment locations and extracted text. |
| unified/ql/lib/unified.qll | New umbrella module importing Unified AST and the new comments library. |
| unified/ql/lib/unified.dbscheme | Regenerated Unified dbscheme to include trivia token entities/table. |
| unified/ql/lib/codeql/unified/Comments.qll | New QL library modeling comments on top of TriviaToken. |
| unified/ql/lib/codeql/unified/Ast.qll | Regenerated Unified AST library adding TriviaToken. |
| shared/tree-sitter-extractor/src/generator/ql_gen.rs | Generate TriviaToken class in emitted QL for desugared languages. |
| shared/tree-sitter-extractor/src/generator/mod.rs | Emit trivia token tables/types conditionally and add generated QL class. |
| shared/tree-sitter-extractor/src/extractor/mod.rs | Extract extra nodes post-desugaring and emit them as trivia tokens. |
Copilot's findings
- Files reviewed: 10/10 changed files
- Comments generated: 3
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.
The Yeast rewriting pass discarded all comments in the input tree, preventing the use of inline expectation tests.
This PR makes it so all such tokens mentioned in the tree-sitter
extrasproperty are emitted asTriviaTokens. The fine-grained separation between, say, line comments and multi-line comments, is not preserved.