Comments (5)
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.
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.
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.
Thanks! This is really useful. I've created an issue to look into this bash-lsp/bash-language-server#74
from tree-sitter-bash.
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)
- errors when declaring a function with a scope indicator '::' but no function keyword
- Process substitution inside parameter expansion breaks tree
- Arithmetic operation inside variable expansion breaks tree HOT 4
- Failed parsing compound operator without brackets in function body.
- Incorrect parsing of (concatenation (simple_expansion) (word)) when word begins with `}` HOT 4
- Error in parameter expansion when mixing single/double quotes HOT 2
- `Cannot read properties of undefined (reading 'apply')` during parsing in the browser sometimes HOT 5
- Backtick comments negatively impact subsequent parsing HOT 1
- Parsing error with extglob inside a pattern with some special prefixes
- Error parsing a complex string HOT 2
- Error parsing GitHub actions `run:` section HOT 2
- Parsing Broken: Remove smallest pattern with nested expansion is broken HOT 2
- `foo$"bar"` is a `translated_string` not a bare `$` followed by string
- Incorrect highlighting of variable substitution with for string with closing braces "\}"
- `herestring_redirect` should be in a `redirected_statement`, not in a bare `command`
- document install of tree sitter bash C on windows HOT 6
- Distinguishing variable definitions from uses HOT 3
- ERROR: Could not find a version that satisfies the requirement tree-sitter-bash (from versions: none) ERROR: No matching distribution found for tree-sitter-bash
- Support for multiple file analysis (Entire project directory) HOT 2
- Semicolon causes ERROR in Parameter Expansion
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tree-sitter-bash.