tree-sitter-sourcepawn

npm version

sourcepawn grammar for tree-sitter

Install

bash npm install tree-sitter-sourcepawn tree-sitter

Usage

```javascript const Parser = require("tree-sitter"); const SourcePawn = require("tree-sitter-sourcepawn");

const parser = new Parser(); parser.setLanguage(SourcePawn);

const sourceCode = ` public Plugin myinfo = { name = "Test", author = "Developer", description = "demonstrating parser", version = PLUGIN_VERSION, url = "http://forums.alliedmods.net" };

public void OnPluginStart() { // your code } `;

const tree = parser.parse(sourceCode); console.log(tree.rootNode.toString()); // (sourcefile [0, 0] - [11, 1] // (structdeclaration [0, 0] - [7, 2] // type: (symbol [0, 7] - [0, 13]) // name: (symbol [0, 14] - [0, 20]) // value: (structconstructor [1, 0] - [7, 1] // (structfieldvalue [2, 4] - [2, 17] // name: (symbol [2, 4] - [2, 8]) // value: (stringliteral [2, 11] - [2, 17])) // (structfieldvalue [3, 4] - [3, 24] // name: (symbol [3, 4] - [3, 10]) // value: (stringliteral [3, 13] - [3, 24])) // (structfieldvalue [4, 4] - [4, 40] // name: (symbol [4, 4] - [4, 15]) // value: (stringliteral [4, 18] - [4, 40])) // (structfieldvalue [5, 4] - [5, 28] // name: (symbol [5, 4] - [5, 11]) // value: (symbol [5, 14] - [5, 28])) // (structfieldvalue [6, 4] - [6, 40] // name: (symbol [6, 4] - [6, 7]) // value: (stringliteral [6, 10] - [6, 40])))) // (functiondeclaration [9, 0] - [11, 1] // (functionvisibility [9, 0] - [9, 6]) // returnType: (type [9, 7] - [9, 11] // (builtintype [9, 7] - [9, 11])) // name: (symbol [9, 12] - [9, 25]) // arguments: (argument_declarations [9, 25] - [9, 27]) // (block [9, 28] - [11, 1] // (comment [10, 4] - [10, 17])))) ```

Note

All available nodes are defined in the grammar.js or src/node-types.json.

Want to help?

You can help by writing tests which are not covered or valid Sourcepawn code, that fails parsing. Tests can be found in the test directory.

If you aren't familiar with tree-sitter tests, you can refer to the official documentation or read some of the available tests.