We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
A Go source file always starts with a package declaration, but the Tree Sitter grammar for Go permits statements at top level:
x = 1 [source_file](https://tree-sitter.github.io/tree-sitter/playground#) [0, 0] - [1, 0] [assignment_statement](https://tree-sitter.github.io/tree-sitter/playground#) [0, 0] - [0, 5] left: [expression_list](https://tree-sitter.github.io/tree-sitter/playground#) [0, 0] - [0, 1] [identifier](https://tree-sitter.github.io/tree-sitter/playground#) [0, 0] - [0, 1] right: [expression_list](https://tree-sitter.github.io/tree-sitter/playground#) [0, 4] - [0, 5] [int_literal](https://tree-sitter.github.io/tree-sitter/playground#) [0, 4] - [0, 5] x := <-ch [source_file](https://tree-sitter.github.io/tree-sitter/playground#) [0, 0] - [1, 0] [short_var_declaration](https://tree-sitter.github.io/tree-sitter/playground#) [0, 0] - [0, 9] left: [expression_list](https://tree-sitter.github.io/tree-sitter/playground#) [0, 0] - [0, 1] [identifier](https://tree-sitter.github.io/tree-sitter/playground#) [0, 0] - [0, 1] right: [expression_list](https://tree-sitter.github.io/tree-sitter/playground#) [0, 5] - [0, 9] [unary_expression](https://tree-sitter.github.io/tree-sitter/playground#) [0, 5] - [0, 9] operand: [identifier](https://tree-sitter.github.io/tree-sitter/playground#) [0, 7] - [0, 9]
The cause is this production:
tree-sitter-go/grammar.js
Lines 105 to 108 in 07d7228
The fix is to remove the reference to _statement here and to add _declaration (var/const/type) to the choices for _top_level_declaration:
Lines 110 to 115 in 07d7228
I wonder whether this was done intentionally because some tools want to process a chunk of statements instead of a complete file.
The text was updated successfully, but these errors were encountered:
This is intentional, so that Tree-sitter can parse things like code snippets inside of markdown files.
Sorry, something went wrong.
Successfully merging a pull request may close this issue.
A Go source file always starts with a package declaration, but the Tree Sitter grammar for Go permits statements at top level:
The cause is this production:
tree-sitter-go/grammar.js
Lines 105 to 108 in 07d7228
The fix is to remove the reference to _statement here and to add _declaration (var/const/type) to the choices for _top_level_declaration:
tree-sitter-go/grammar.js
Lines 110 to 115 in 07d7228
I wonder whether this was done intentionally because some tools want to process a chunk of statements instead of a complete file.
The text was updated successfully, but these errors were encountered: