Giter Site home page Giter Site logo

Comments (5)

maxbrunsfeld avatar maxbrunsfeld commented on June 27, 2024 2

Parsing this file with 0.13.2, I get this output:

$ tree-sitter parse test.sh 

(program [0, 0] - [6, 0]
  (variable_assignment [0, 0] - [0, 20]
    (variable_name [0, 0] - [0, 10])
    (word [0, 11] - [0, 20]))
  (variable_assignment [1, 0] - [1, 22]
    (variable_name [1, 0] - [1, 11])
    (word [1, 12] - [1, 22]))
  (if_statement [3, 0] - [6, 0]
    (test_command [3, 3] - [3, 37]
      (binary_expression [3, 6] - [3, 34]
        (simple_expansion [3, 6] - [3, 17]
          (variable_name [3, 7] - [3, 17]))
        (test_operator [3, 18] - [3, 21])
        (simple_expansion [3, 22] - [3, 34]
          (variable_name [3, 23] - [3, 34]))))
    (command [4, 2] - [4, 54]
      (command_name [4, 2] - [4, 7]
        (word [4, 2] - [4, 7]))
      (word [4, 8] - [4, 17])
      (word [4, 18] - [4, 23])
      (expansion [4, 24] - [4, 37]
        (variable_name [4, 26] - [4, 36]))
      (file_redirect [4, 38] - [4, 54]
        (expansion [4, 40] - [4, 54]
          (variable_name [4, 42] - [4, 53]))))
    (command [5, 0] - [5, 1]
      (command_name [5, 0] - [5, 1]
        (word [5, 0] - [5, 1])))))
test.sh	7 ms	MISSING fi [6, 0] - [6, 0]

The last child of the if_statement is a fi token that is "missing" (i.e. tree-sitter realized that it was missing and inserted it for error recovery). I just realized that the SyntaxNode.isMissing() method was not declared in the typescript declarations file. That is now fixed.

In bash-language-server, I'm guessing you're probably not checking if nodes are missing. These nodes will have zero size (e.g. startPosition equals endPosition).

from tree-sitter-bash.

maxbrunsfeld avatar maxbrunsfeld commented on June 27, 2024 1

Another thing that might be useful is that you can check whether a parent node contains any errors of any kind using the SyntaxNode.hasError() method. This will return true of the node contains any ERROR nodes or any missing nodes.

from tree-sitter-bash.

skovhus avatar skovhus commented on June 27, 2024

No, we were actually just checking if the tree sitter returned the ERROR type.

Didn’t know the grammar supported error recovery. Really cool. I guess we could use that in bash-language-server to show hints.

from tree-sitter-bash.

skovhus avatar skovhus commented on June 27, 2024

Thanks! This is really useful. I've created an issue to look into this bash-lsp/bash-language-server#74

from tree-sitter-bash.

maxbrunsfeld avatar maxbrunsfeld commented on June 27, 2024

Great! I'm going to close this out since I think the parser is behaving correctly in this regard.

from tree-sitter-bash.

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.