Skip to content

feat: populate source spans on all AST nodes#9

Merged
mpecan merged 3 commits intomainfrom
feat/populate-spans-to-main
Mar 25, 2026
Merged

feat: populate source spans on all AST nodes#9
mpecan merged 3 commits intomainfrom
feat/populate-spans-to-main

Conversation

@mpecan
Copy link
Copy Markdown
Owner

@mpecan mpecan commented Mar 25, 2026

Summary

Follows up on #7 (AST enrichment) to actually populate spans on all nodes.

  • Add last_token_end tracking to Lexer for precise span endpoints
  • Add peek_pos(), span_from(), spanned() helpers to Parser
  • Populate spans on all node types: Command, Word, Pipeline, List, Redirect, HereDoc, compound commands, conditional expressions, Negation, Time
  • Fix source_text() char-index-to-byte-offset conversion
  • 17 span coverage tests (100% line coverage on span logic)

Test plan

  • 103 tests pass (60 unit + 37 integration + 6 doc)
  • cargo clippy --all-targets -- -D warnings clean
  • Span-related code in ast.rs at 100% line coverage

🤖 Generated with Claude Code

mpecan and others added 3 commits March 25, 2026 08:38
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 mpecan merged commit b8be160 into main Mar 25, 2026
4 checks passed
@mpecan mpecan deleted the feat/populate-spans-to-main branch March 25, 2026 07:53
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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant