GDScript grammar for tree-sitter.
Note: Some commits may have been missed.
git log --oneline --no-merges modules/gdscript- Test grammar
npm run genTest
- Test scanner
- Edit "src/scanner.c"
npm run test, no need to generate.
- Build prebuilds
npm run genTestnpm run prebuild
- Build with node-gyp
npm run genTestnpm install node-gypnode-gyp rebuild
- Edit
- Write tests in corpus to express behavior.
- Make grammar or scanner edits.
- See above for running tests.
npm run format- Commit changes.
- If commit is an issue fix, prefix message with
fix #<issue-number>: - List the rules changed in commit message.
- Note what rules need to be updated in nvim-treesitter queries.
- If commit is an issue fix, prefix message with
- Commit generated files with the latest non-wip commit.
- Push
- Release
- Manually edit version in package files: CMakeLists.txt, Cargo.toml, Makefile, pyproject.toml, tree-sitter.json
npm version --git-tag-version false <major, minor, patch>git tag -a v<version>git push && git push --tagscargo packagecargo publish
Note: node-gyp-build will check for binaries in both build and prebuilds
directories.
At the time of writing, the official GDScript parser built into Godot ignores comments and regions and does not have them as part of the code's parsed abstract syntax tree (AST).
In this parser, however, because it is used for syntax highlighting and folding support, we need to parse comments and regions and have them as part of the AST, which poses some challenges. The AST is meant to be a tree whose structure captures the nesting of the code.
Consider this snippet:
func test() -> void:
if true:
# Comment
print("if body")The call to the print() function is the body of the if statement. But where does the comment go? Is it part of the if statement's body or does it end the if statement's body and become its own sibling node?
By convention, comments that follow end the if statement's body are treated as belonging to the if statement's body. More generally, the indentation of comments and region markers is ignored by the parser. The code above will be parsed like this:
(function_definition
name: (name)
parameters: (parameters)
return_type: (type
(identifier))
body: (body
(if_statement
condition: (true)
body: (body
(comment)
(expression_statement
(call
(identifier)
arguments: (arguments
(string)))))))If you want to rebuild the indentation of comments and region markers, you can use the comment node's start column/byte offset in the source code and scan back to the previous line return character to determine the source indentation level.