Comments (10)
I'll get through it and let you know.
(Sadly, I see that proper abd efficient implementation will require more time i can spare. Sorry.)
from py-tree-sitter.
Very good. My problem has been solved. Thank you very much.
I think you can add an attribute to identifier node to get the text of the node. Because identifier node text is a user-defined value, getting this value may be more useful.
I just put forward my opinion. You can think about it again.
from py-tree-sitter.
any update on this matter, can we use the .text to get the identifier value now?
from py-tree-sitter.
Issue Label Bot is not confident enough to auto-label this issue. See dashboard for more details.
from py-tree-sitter.
Currently, the way to get the text for an ast node is to use the Node.start_byte
and node.end_byte
properties:
tree = parser.parse(source_code_bytes)
# ...
text = source_code_bytes[node.start_byte:node.end_byte]
Does that help? I think it'd be possible to add a more convenient API also, but I'm not sure what it should be.
from py-tree-sitter.
Would it be possible to support a .text
property as is done in the JavaScript bindings?
from py-tree-sitter.
Regarding .text
for nodes, roughly, I think the way it is done in node-tree-sitter is something like:
-
When a SyntaxNode is created, it is passed a tree in its constructor: https://github.com/tree-sitter/node-tree-sitter/blob/209e734e8df0bc0b79ef0af222843a92ce9c5c8c/index.js#L47-L50
-
If the node's
.text()
is used, the associated tree's.getText()
is called: https://github.com/tree-sitter/node-tree-sitter/blob/209e734e8df0bc0b79ef0af222843a92ce9c5c8c/index.js#L76-L78 -
That
.getText()
was arranged for whenparse
was called to create the tree that the node is a part of -- if it was a string that was parsed, this is retained as part of the tree: : https://github.com/tree-sitter/node-tree-sitter/blob/209e734e8df0bc0b79ef0af222843a92ce9c5c8c/index.js#L271-L293
That's not the whole story it seems, but at any rate, it gives some idea of possibly what could be done in the case of py-tree-sitter.
from py-tree-sitter.
Is there any plan about it? I can handle the implementation.
from py-tree-sitter.
I was working on an implementation in #37, but am not attached to it.
I don't know if anyone else is working on this functionality.
If you do end up going ahead with something and haven't looked at the discussion in #37, I think it might be good to take a look.
from py-tree-sitter.
node.text was recently merged, it should work on HEAD
from py-tree-sitter.
Related Issues (20)
- Documentation is required.
- Is it possible to understand if an object is an instance of a certain class that may be defined in another file?
- How to use tree-sitter in Windows 10? HOT 6
- Special case not managed by the parser, when an expression is split without a backslash and the second line is dedented. HOT 4
- Example mismatch HOT 1
- Captures are not grouped HOT 3
- How to sync node after code edit? HOT 1
- README.md needs updates
- Tree-sitter Fails with Core Dump on Processing Large Input Code File HOT 4
- query failing in py-tree-sitter but compiling in tree-sitter playground HOT 1
- a __main__.py to build `vendor/tree-sitter-X` from command line HOT 1
- [bug] Cannot build a library in a directory containing two parsers. HOT 5
- The Python parser appears to be parsing comments and strings with unmatched parentheses as code HOT 2
- py-tree-sitter is 10x slower than lezer-parser HOT 9
- FileNotFoundError: [Errno 2] No such file or directory: 'tree-sitter-java/src/parser.c' HOT 2
- UTF-16 encoding support is wanted HOT 1
- Can't install tree-sitter-python HOT 1
- [tree-sitter-python] `No matching distribution found for tree-sitter-python` HOT 1
- Broken (?) README instructions to pip install pre-compiled binary wheels HOT 1
- Python 3.12 support for version 0.21.0 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from py-tree-sitter.