GithubHelp home page GithubHelp logo

Comments (7)

ubolonton avatar ubolonton commented on May 1, 2024 1

I think it's the same issue as tree-sitter/tree-sitter#567.
Basically the cursor can't walk out of the starting node, so it can't know which field it's on within the parent node.
We definitely should document this better.

from elisp-tree-sitter.

mathrick avatar mathrick commented on May 1, 2024 1

I did some more reading, and it turns out I was confused about the meaning of fields. I was under the impression that fields were the properties of nodes, but in reality, they're properties of the relationship between a parent and its children. So the API really doesn't have a concept of "a node's field", only "given child's field".

from elisp-tree-sitter.

ubolonton avatar ubolonton commented on May 1, 2024 1

Yeah, field is basically the nickname by which the parent calls the child at home.

Semi-formally, it's the (name of the) edge between the parent node and the child node.

from elisp-tree-sitter.

mathrick avatar mathrick commented on May 1, 2024

This is apparently an issue for all traversal utils, for example:

;; This will also always return nil
(defun node-field (node)
  (block nil
    (tsc-traverse-do ([field] node)
     (return field))))

from elisp-tree-sitter.

mathrick avatar mathrick commented on May 1, 2024

Hmm, is it a shortcoming in the underlying treesitter API, or is there some functionality that's present in the base API but not exposed by tree-sitter.el? Because as things are right now, there's no straightforward way to get a node's field without gymnastics involving cursors and weird edge cases (see also #274). Something like tsc-node-field sounds like it should exist.

from elisp-tree-sitter.

mathrick avatar mathrick commented on May 1, 2024

Also, I don't know whether that is a thing that even makes sense to want, but this limitation means we can never have a field on the root node of a tree.

from elisp-tree-sitter.

sogaiu avatar sogaiu commented on May 1, 2024

Yes, I found this confusing as well, but IIUC, this is close to my impression of how things work (my impression is vague (^^; ):

in reality, they're properties of the relationship between a parent and its children. So the API really doesn't have a concept of "a node's field", only "given child's field".

from elisp-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.