feat: populate source spans on all AST nodes#9
Merged
Conversation
Track source positions throughout the parser so every Node carries a correct Span. Spans use character indices matching Token.pos semantics. - Add `last_token_end` tracking to Lexer for precise span endpoints - Add `peek_pos()`, `span_from()`, `spanned()` helpers to Parser - Populate spans on: Command, Word, Pipeline, List, Redirect, HereDoc, all compound commands (if/while/for/case/select/function/coproc/subshell/ brace-group/arith), conditional expressions, Negation, Time - Fix `source_text()` to correctly convert char indices to byte offsets - Add tests: source_text on commands, pipelines, lists, and synthetic nodes Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add 13 new tests covering source_text() and span tracking: - Span past source end (fallback branch) - Multi-byte UTF-8 characters (char-index-to-byte-offset conversion) - Compound commands: if, while, for, case, function, subshell, brace group - Conditional expressions [[ ]] - Negation (!) - Redirects (> file.txt) - Multi-line source (separate top-level nodes) All span-related code in ast.rs now has 100% line coverage. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
## Summary - Track source positions throughout the parser so every `Node` carries a correct `Span` - Add `last_token_end` to the Lexer for precise span endpoints (avoids including trailing whitespace) - Add `peek_pos()`, `span_from()`, `spanned()` helpers to the Parser - Fix `source_text()` to correctly convert character indices to byte offsets - Populate spans on all node types: Command, Word, Pipeline, List, Redirect, HereDoc, compound commands, conditional expressions, Negation, Time ## Test plan - [x] All 90 tests pass (47 unit + 37 integration + 6 doc) - [x] `cargo clippy --all-targets -- -D warnings` clean - [x] New tests verify `source_text()` returns correct substrings for commands, words, pipelines, lists, and synthetic nodes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
mpecan
added a commit
that referenced
this pull request
Mar 25, 2026
🤖 I have created a release *beep* *boop* --- ## [0.1.7](rable-v0.1.6...rable-v0.1.7) (2026-03-25) ### Features * populate source spans on all AST nodes ([0e32c37](0e32c37)) * populate source spans on all AST nodes ([#8](#8)) ([a8c92e8](a8c92e8)) * populate source spans on all AST nodes ([#9](#9)) ([b8be160](b8be160)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
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.
Summary
Follows up on #7 (AST enrichment) to actually populate spans on all nodes.
last_token_endtracking to Lexer for precise span endpointspeek_pos(),span_from(),spanned()helpers to Parsersource_text()char-index-to-byte-offset conversionTest plan
cargo clippy --all-targets -- -D warningsclean🤖 Generated with Claude Code