Skip to content

feat: populate source spans on all AST nodes#8

Merged
mpecan merged 2 commits intofeat/ast-enrichmentfrom
feat/populate-spans
Mar 25, 2026
Merged

feat: populate source spans on all AST nodes#8
mpecan merged 2 commits intofeat/ast-enrichmentfrom
feat/populate-spans

Conversation

@mpecan
Copy link
Copy Markdown
Owner

@mpecan mpecan commented Mar 25, 2026

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

  • All 90 tests pass (47 unit + 37 integration + 6 doc)
  • cargo clippy --all-targets -- -D warnings clean
  • New tests verify source_text() returns correct substrings for commands, words, pipelines, lists, and synthetic nodes

🤖 Generated with Claude Code

mpecan and others added 2 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>
@mpecan mpecan merged commit a8c92e8 into feat/ast-enrichment Mar 25, 2026
@mpecan mpecan deleted the feat/populate-spans branch March 25, 2026 07:48
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