Code Monkey home page Code Monkey logo

Comments (10)

majkrzak avatar majkrzak commented on May 27, 2024 3

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.

fengzhangyin avatar fengzhangyin commented on May 27, 2024 2

@maxbrunsfeld

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.

bdqnghi avatar bdqnghi commented on May 27, 2024 2

any update on this matter, can we use the .text to get the identifier value now?

from py-tree-sitter.

issue-label-bot avatar issue-label-bot commented on May 27, 2024

Issue Label Bot is not confident enough to auto-label this issue. See dashboard for more details.

from py-tree-sitter.

maxbrunsfeld avatar maxbrunsfeld commented on May 27, 2024

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.

AlexGustafsson avatar AlexGustafsson commented on May 27, 2024

Would it be possible to support a .text property as is done in the JavaScript bindings?

from py-tree-sitter.

sogaiu avatar sogaiu commented on May 27, 2024

Regarding .text for nodes, roughly, I think the way it is done in node-tree-sitter is something like:

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.

majkrzak avatar majkrzak commented on May 27, 2024

Is there any plan about it? I can handle the implementation.

from py-tree-sitter.

sogaiu avatar sogaiu commented on May 27, 2024

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.

lunixbochs avatar lunixbochs commented on May 27, 2024

node.text was recently merged, it should work on HEAD

from py-tree-sitter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.