Coder Social home page Coder Social logo

Comments (3)

ahlinc avatar ahlinc commented on June 12, 2024 1

The exposed token is ", but the underlying source text has the full original token.

Yes, the token has a correct range that allows to access a correct piece in an original input.
But with predicates that is much slower because they work outside of a query engine as post filtering and require access to an input.

If there will be correct terminals then queries like bellow would work without predicates:

; Strings with only triple single quotes
  (string "'''" @quote) @str

; Strings with triple quotes
  (string [ "'''" "\"\"\"" ] @quote) @str

And in a visual tree representation there will be no misunderstanding:

Screenshot from 2023-03-11 19-07-50

I think it should become a bad practice to hide actual terminals that define syntax structure and replace them to something another. But for now this exist in this grammar for historical reasons.

from tree-sitter-python.

tausbn avatar tausbn commented on June 12, 2024

I'm not sure I see what the problem is. The exposed token is ", but the underlying source text has the full original token.

For instance, the following query can be used to match only strings delimited with triple (single) quotes:

(
  (string "\"" @quote) @str
  (#match? @quote "'''")
)

from tree-sitter-python.

andymass avatar andymass commented on June 12, 2024

Have a similar problem, I'm looking for a query to target only the quote characters, not the entire string. For many languages this works with (_ "\"" "\"") or similar, but not for python. Is there an easy query like this?

from tree-sitter-python.

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.