Skip to content

Yeast/Unified: Extract comments#21981

Open
asgerf wants to merge 5 commits into
github:mainfrom
asgerf:yeast/comments
Open

Yeast/Unified: Extract comments#21981
asgerf wants to merge 5 commits into
github:mainfrom
asgerf:yeast/comments

Conversation

@asgerf

@asgerf asgerf commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

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 extras property are emitted as TriviaTokens. The fine-grained separation between, say, line comments and multi-line comments, is not preserved.

@asgerf asgerf added the no-change-note-required This PR does not need a change note label Jun 12, 2026
@asgerf asgerf marked this pull request as ready for review June 12, 2026 14:43
@asgerf asgerf requested review from a team as code owners June 12, 2026 14:43
Copilot AI review requested due to automatic review settings June 12, 2026 14:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 TriviaToken class and associated *_trivia_tokeninfo table when desugaring is enabled.
  • Update extraction to traverse the original tree-sitter parse tree for extra nodes after desugaring and emit them as TriviaTokens 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

Comment thread unified/ql/lib/codeql/unified/Comments.qll
Comment thread unified/ql/test/library-tests/comments/comments.expected
Comment thread unified/ql/lib/codeql/unified/Comments.qll
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-change-note-required This PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants