Skip to content

Collect source text from ParseCallback during parsing - #178

Merged
ObserverOfTime merged 1 commit into
tree-sitter:masterfrom
ALancki1:collect-parsecallback-source-text
Nov 10, 2026
Merged

ObserverOfTime merged 1 commit into
tree-sitter:masterfrom
ALancki1:collect-parsecallback-source-text

Conversation

@ALancki1

@ALancki1 ALancki1 commented Apr 2, 2026

Copy link
Copy Markdown

This change collects source text returned by ParseCallback during parsing and stores it in the resulting Tree.

Previously, trees created from ParseCallback did not retain source text, causing methods like getText() and Node.getText() to return null. This change enables text-related APIs for callback-based parsing.

This also updates the callback parsing test to assert the new behavior.

Fixes #126

@ALancki1

ALancki1 commented Apr 2, 2026

Copy link
Copy Markdown
Author

Thanks for taking a look. From my diff, the intended changes in Parser.java are only:

  • collecting callback text into a StringBuilder
  • appending each returned chunk
  • passing the collected text into Tree

I don’t think I changed the null-language check itself. Were you pointing to a specific issue with the added StringBuilder change in that hunk?

@ALancki1

ALancki1 commented Apr 2, 2026

Copy link
Copy Markdown
Author

Good point. I switched this to collect bytes instead of using a StringBuilder, and I also used the callback offset to avoid duplicating overlapping chunks.

@ObserverOfTime
ObserverOfTime force-pushed the collect-parsecallback-source-text branch 2 times, most recently from c36a49c to a35a7ec Compare November 10, 2026 15:55
Co-Authored-By: ObserverOfTime <chronobserver@disroot.org>
@ObserverOfTime
ObserverOfTime force-pushed the collect-parsecallback-source-text branch from a35a7ec to 36e302a Compare November 10, 2026 16:02
@ObserverOfTime
ObserverOfTime merged commit 68560ff into tree-sitter:master Nov 10, 2026
14 of 15 checks passed
@ObserverOfTime

Copy link
Copy Markdown
Member

Thanks, I made a few changes to pass the result as bytes instead of converting to a string.

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.

Collect source bytes from ParseCallback

3 participants