Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.13.2 missing parsing errors #27

Closed
skovhus opened this issue Aug 6, 2018 · 5 comments
Closed

0.13.2 missing parsing errors #27

skovhus opened this issue Aug 6, 2018 · 5 comments

Comments

@skovhus
Copy link
Contributor

skovhus commented Aug 6, 2018

0.13.1 error on a file like this with a missing fi:

PATH_INPUT=src/in.js
PATH_OUTPUT=src/out.js

if [[ $PATH_INPUT -nt $PATH_OUTPUT ]]; then
  babel --compact false ${PATH_INPUT} > ${PATH_OUTPUT}
f

I guess this is a regression from 0.13.1? Didn't investigate if this is due to 6ff7fe3

@maxbrunsfeld
Copy link
Contributor

maxbrunsfeld commented Aug 6, 2018

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).

@skovhus
Copy link
Contributor Author

skovhus commented Aug 6, 2018

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.

@maxbrunsfeld
Copy link
Contributor

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.

@skovhus
Copy link
Contributor Author

skovhus commented Aug 6, 2018

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

@maxbrunsfeld
Copy link
Contributor

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

ulrikstrid pushed a commit to ulrikstrid/ligo that referenced this issue May 25, 2021
Problem: When we have a missing token, tree-sitter won't report an ERROR
node but instead will create an empty node.

Solution: We check if such node exists, and if so, rename it so it's an
ERROR node. Note tree-sitter has some functions to report whether an
error exists, but it seems the Haskell version doesn't really bridge
such function. Please see:
tree-sitter/tree-sitter-bash#27 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants