Skip to content

Unparsing with tree-sitter? #2077

Closed Answered by ahlinc
nalzok asked this question in Q&A
Feb 7, 2023 · 4 comments · 5 replies
Discussion options

You must be logged in to vote

As @ahelwer said it isn't supported in the same sense of like it exists in Python because Tree-sitter doesn't store original text pieces in all leaf nodes, instead of that it just stores ranges that every node occupy in an original text.
It depends what is a purpose of unparsing:

  • If to restore a piece of source text based on some node than it's easy to get a needed node position as a byte range and get a slice of input related to the node range.
  • If to render to a text some modified AST, then it's not supported because Tree-sitter was build around idea of immutable trees.

Replies: 4 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by nalzok
Comment options

You must be logged in to vote
5 replies
@ahlinc
Comment options

@verhovsky
Comment options

@ahlinc
Comment options

@conartist6
Comment options

@conartist6
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
7 participants
Converted from issue

This discussion was converted from issue #2074 on February 07, 2023 16:44.