tree-sitter-ucode 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +158 -0
- package/binding.gyp +35 -0
- package/bindings/node/binding.cc +19 -0
- package/bindings/node/index.d.ts +27 -0
- package/bindings/node/index.js +10 -0
- package/grammar.js +903 -0
- package/package.json +52 -0
- package/queries/highlights.scm +163 -0
- package/queries/locals.scm +105 -0
- package/queries/tags.scm +104 -0
- package/src/grammar.json +5033 -0
- package/src/node-types.json +2584 -0
- package/src/parser.c +33948 -0
- package/src/scanner.c +198 -0
- package/src/tree_sitter/alloc.h +54 -0
- package/src/tree_sitter/array.h +330 -0
- package/src/tree_sitter/parser.h +286 -0
- package/tmpl/grammar.js +67 -0
- package/tmpl/queries/highlights.scm +23 -0
- package/tmpl/queries/injections.scm +8 -0
- package/tmpl/queries/locals.scm +3 -0
- package/tmpl/src/grammar.json +243 -0
- package/tmpl/src/node-types.json +230 -0
- package/tmpl/src/parser.c +707 -0
- package/tmpl/src/scanner.c +169 -0
- package/tmpl/src/tree_sitter/alloc.h +54 -0
- package/tmpl/src/tree_sitter/array.h +330 -0
- package/tmpl/src/tree_sitter/parser.h +286 -0
- package/tree-sitter-ucode.wasm +0 -0
- package/tree-sitter-ucode_tmpl.wasm +0 -0
- package/tree-sitter.json +54 -0
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tree-sitter-ucode",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Ucode grammar for tree-sitter",
|
|
5
|
+
"repository": "https://github.com/m00qek/tree-sitter-ucode",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "bindings/node",
|
|
8
|
+
"types": "bindings/node",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"incremental",
|
|
11
|
+
"parsing",
|
|
12
|
+
"tree-sitter",
|
|
13
|
+
"ucode",
|
|
14
|
+
"openwrt"
|
|
15
|
+
],
|
|
16
|
+
"files": [
|
|
17
|
+
"grammar.js",
|
|
18
|
+
"tree-sitter.json",
|
|
19
|
+
"binding.gyp",
|
|
20
|
+
"prebuilds/**",
|
|
21
|
+
"bindings/node/*",
|
|
22
|
+
"queries/*",
|
|
23
|
+
"src/**",
|
|
24
|
+
"tmpl/grammar.js",
|
|
25
|
+
"tmpl/src/**",
|
|
26
|
+
"tmpl/queries/*",
|
|
27
|
+
"*.wasm"
|
|
28
|
+
],
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"node-addon-api": "^8.3.1",
|
|
31
|
+
"node-gyp-build": "^4.8.4"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"prebuildify": "^6.0.1",
|
|
35
|
+
"tree-sitter-cli": "^0.26.0"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"tree-sitter": "^0.22.0"
|
|
39
|
+
},
|
|
40
|
+
"peerDependenciesMeta": {
|
|
41
|
+
"tree-sitter": {
|
|
42
|
+
"optional": true
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"install": "node-gyp-build",
|
|
47
|
+
"build": "tree-sitter generate && tree-sitter generate tmpl/grammar.js --output tmpl/src && node-gyp-build && tree-sitter build --output ucode.so . && tree-sitter build --output ucode_tmpl.so ./tmpl",
|
|
48
|
+
"test": "tree-sitter test && tree-sitter test -p tmpl",
|
|
49
|
+
"prestart": "tree-sitter build --wasm",
|
|
50
|
+
"start": "tree-sitter playground"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
; Highlight queries for ucode.
|
|
2
|
+
; Capture names follow the tree-sitter / nvim-treesitter standard.
|
|
3
|
+
|
|
4
|
+
; -------------------------------------------------------------------------
|
|
5
|
+
; Identifiers
|
|
6
|
+
; -------------------------------------------------------------------------
|
|
7
|
+
|
|
8
|
+
(identifier) @variable
|
|
9
|
+
(property_identifier) @variable.member
|
|
10
|
+
(shorthand_property_identifier) @variable.member
|
|
11
|
+
(statement_identifier) @label
|
|
12
|
+
|
|
13
|
+
; -------------------------------------------------------------------------
|
|
14
|
+
; Built-in / special values
|
|
15
|
+
; -------------------------------------------------------------------------
|
|
16
|
+
|
|
17
|
+
(this) @variable.builtin
|
|
18
|
+
[(true) (false)] @boolean
|
|
19
|
+
(null) @constant.builtin
|
|
20
|
+
|
|
21
|
+
; -------------------------------------------------------------------------
|
|
22
|
+
; Comments
|
|
23
|
+
; -------------------------------------------------------------------------
|
|
24
|
+
|
|
25
|
+
(comment) @comment @spell
|
|
26
|
+
|
|
27
|
+
; -------------------------------------------------------------------------
|
|
28
|
+
; Shebang
|
|
29
|
+
; -------------------------------------------------------------------------
|
|
30
|
+
|
|
31
|
+
(hash_bang_line) @keyword.directive
|
|
32
|
+
|
|
33
|
+
; -------------------------------------------------------------------------
|
|
34
|
+
; Literals
|
|
35
|
+
; -------------------------------------------------------------------------
|
|
36
|
+
|
|
37
|
+
(number) @number
|
|
38
|
+
|
|
39
|
+
(string) @string
|
|
40
|
+
(string (escape_sequence) @string.escape)
|
|
41
|
+
|
|
42
|
+
(template_string) @string
|
|
43
|
+
(template_string (escape_sequence) @string.escape)
|
|
44
|
+
(template_substitution "${" @punctuation.special)
|
|
45
|
+
(template_substitution "}" @punctuation.special)
|
|
46
|
+
|
|
47
|
+
(regex) @string.regexp
|
|
48
|
+
|
|
49
|
+
; -------------------------------------------------------------------------
|
|
50
|
+
; Functions — definitions
|
|
51
|
+
; -------------------------------------------------------------------------
|
|
52
|
+
|
|
53
|
+
(function_declaration
|
|
54
|
+
name: (identifier) @function)
|
|
55
|
+
|
|
56
|
+
(function_forward_declaration
|
|
57
|
+
name: (identifier) @function)
|
|
58
|
+
|
|
59
|
+
(function_expression
|
|
60
|
+
name: (identifier) @function)
|
|
61
|
+
|
|
62
|
+
; Method-style object entries: { key: function() {} } or { key: () => {} }
|
|
63
|
+
(pair
|
|
64
|
+
key: (property_identifier) @function.method
|
|
65
|
+
value: [(function_expression) (arrow_function)])
|
|
66
|
+
|
|
67
|
+
; -------------------------------------------------------------------------
|
|
68
|
+
; Functions — calls
|
|
69
|
+
; -------------------------------------------------------------------------
|
|
70
|
+
|
|
71
|
+
(call_expression
|
|
72
|
+
function: (identifier) @function.call)
|
|
73
|
+
|
|
74
|
+
(call_expression
|
|
75
|
+
function: (member_expression
|
|
76
|
+
property: (property_identifier) @function.method.call))
|
|
77
|
+
|
|
78
|
+
; -------------------------------------------------------------------------
|
|
79
|
+
; Parameters
|
|
80
|
+
; -------------------------------------------------------------------------
|
|
81
|
+
|
|
82
|
+
(formal_parameters (identifier) @variable.parameter)
|
|
83
|
+
(rest_element (identifier) @variable.parameter)
|
|
84
|
+
(arrow_function parameter: (identifier) @variable.parameter)
|
|
85
|
+
|
|
86
|
+
; -------------------------------------------------------------------------
|
|
87
|
+
; Keywords — conditional
|
|
88
|
+
; -------------------------------------------------------------------------
|
|
89
|
+
|
|
90
|
+
["if" "elif" "else" "endif"] @keyword.conditional
|
|
91
|
+
["switch" "case" "default"] @keyword.conditional
|
|
92
|
+
|
|
93
|
+
; -------------------------------------------------------------------------
|
|
94
|
+
; Keywords — loops
|
|
95
|
+
; -------------------------------------------------------------------------
|
|
96
|
+
|
|
97
|
+
["for" "endfor" "while" "endwhile"] @keyword.repeat
|
|
98
|
+
|
|
99
|
+
; -------------------------------------------------------------------------
|
|
100
|
+
; Keywords — functions
|
|
101
|
+
; -------------------------------------------------------------------------
|
|
102
|
+
|
|
103
|
+
["function" "endfunction"] @keyword.function
|
|
104
|
+
|
|
105
|
+
; -------------------------------------------------------------------------
|
|
106
|
+
; Keywords — control
|
|
107
|
+
; -------------------------------------------------------------------------
|
|
108
|
+
|
|
109
|
+
"return" @keyword.return
|
|
110
|
+
["break" "continue"] @keyword
|
|
111
|
+
|
|
112
|
+
; -------------------------------------------------------------------------
|
|
113
|
+
; Keywords — exceptions
|
|
114
|
+
; -------------------------------------------------------------------------
|
|
115
|
+
|
|
116
|
+
["try" "catch"] @keyword.exception
|
|
117
|
+
|
|
118
|
+
; -------------------------------------------------------------------------
|
|
119
|
+
; Keywords — modules
|
|
120
|
+
; -------------------------------------------------------------------------
|
|
121
|
+
|
|
122
|
+
["import" "export"] @keyword.import
|
|
123
|
+
["as" "from"] @keyword.import
|
|
124
|
+
; Dynamic import() uses a named node, not an anonymous string
|
|
125
|
+
(import_expression (import) @keyword.import)
|
|
126
|
+
|
|
127
|
+
; -------------------------------------------------------------------------
|
|
128
|
+
; Keywords — storage / operators
|
|
129
|
+
; -------------------------------------------------------------------------
|
|
130
|
+
|
|
131
|
+
["const" "let"] @keyword.storage
|
|
132
|
+
["delete" "in"] @keyword.operator
|
|
133
|
+
|
|
134
|
+
; -------------------------------------------------------------------------
|
|
135
|
+
; Operators
|
|
136
|
+
; -------------------------------------------------------------------------
|
|
137
|
+
|
|
138
|
+
[
|
|
139
|
+
"=" "+=" "-=" "*=" "/=" "%=" "**="
|
|
140
|
+
"^=" "&=" "|=" ">>=" "<<=" "&&=" "||=" "??="
|
|
141
|
+
] @operator
|
|
142
|
+
|
|
143
|
+
[
|
|
144
|
+
"+" "-" "*" "/" "%" "**"
|
|
145
|
+
"&" "|" "^" "~" "<<" ">>"
|
|
146
|
+
"!" "&&" "||" "??"
|
|
147
|
+
"==" "!=" "===" "!=="
|
|
148
|
+
"<" ">" "<=" ">="
|
|
149
|
+
"++" "--"
|
|
150
|
+
"=>"
|
|
151
|
+
"..."
|
|
152
|
+
] @operator
|
|
153
|
+
|
|
154
|
+
(optional_chain) @operator
|
|
155
|
+
(ternary_expression "?" @operator)
|
|
156
|
+
(ternary_expression ":" @operator)
|
|
157
|
+
|
|
158
|
+
; -------------------------------------------------------------------------
|
|
159
|
+
; Punctuation
|
|
160
|
+
; -------------------------------------------------------------------------
|
|
161
|
+
|
|
162
|
+
["," ";"] @punctuation.delimiter
|
|
163
|
+
["(" ")" "[" "]" "{" "}"] @punctuation.bracket
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
; Locals queries for ucode.
|
|
2
|
+
; Used by editors for rename, go-to-definition, and scope-aware highlight.
|
|
3
|
+
|
|
4
|
+
; -------------------------------------------------------------------------
|
|
5
|
+
; Scopes
|
|
6
|
+
; -------------------------------------------------------------------------
|
|
7
|
+
|
|
8
|
+
(function_declaration) @local.scope
|
|
9
|
+
; function_forward_declaration has no body — it is a definition, not a scope
|
|
10
|
+
(function_expression) @local.scope
|
|
11
|
+
(arrow_function) @local.scope
|
|
12
|
+
; statement_block provides block scoping for let/const
|
|
13
|
+
(statement_block) @local.scope
|
|
14
|
+
; for loops scope their initialiser variable(s) to the loop body
|
|
15
|
+
(for_statement) @local.scope
|
|
16
|
+
(for_alt_statement) @local.scope
|
|
17
|
+
(for_in_statement) @local.scope
|
|
18
|
+
(for_in_alt_statement) @local.scope
|
|
19
|
+
; catch clause scopes its parameter to the handler body
|
|
20
|
+
(catch_clause) @local.scope
|
|
21
|
+
|
|
22
|
+
; -------------------------------------------------------------------------
|
|
23
|
+
; Definitions — functions
|
|
24
|
+
; -------------------------------------------------------------------------
|
|
25
|
+
|
|
26
|
+
; Declaration and forward-declaration names belong to the *enclosing* scope
|
|
27
|
+
; so that callers outside the function body can resolve them.
|
|
28
|
+
(function_declaration
|
|
29
|
+
name: (identifier) @local.definition.function
|
|
30
|
+
(#set! definition.function.scope parent))
|
|
31
|
+
|
|
32
|
+
(function_forward_declaration
|
|
33
|
+
name: (identifier) @local.definition.function
|
|
34
|
+
(#set! definition.function.scope parent))
|
|
35
|
+
|
|
36
|
+
; Named function expressions (let f = function foo() {}) keep their name
|
|
37
|
+
; *inside* the expression scope — foo is only visible for self-recursion,
|
|
38
|
+
; not to the surrounding block. No (#set! parent) here.
|
|
39
|
+
(function_expression
|
|
40
|
+
name: (identifier) @local.definition.function)
|
|
41
|
+
|
|
42
|
+
; -------------------------------------------------------------------------
|
|
43
|
+
; Definitions — variables
|
|
44
|
+
; -------------------------------------------------------------------------
|
|
45
|
+
|
|
46
|
+
(variable_declarator
|
|
47
|
+
name: (identifier) @local.definition.var)
|
|
48
|
+
|
|
49
|
+
; -------------------------------------------------------------------------
|
|
50
|
+
; Definitions — parameters
|
|
51
|
+
; -------------------------------------------------------------------------
|
|
52
|
+
|
|
53
|
+
(formal_parameters (identifier) @local.definition.parameter)
|
|
54
|
+
(rest_element (identifier) @local.definition.parameter)
|
|
55
|
+
(arrow_function parameter: (identifier) @local.definition.parameter)
|
|
56
|
+
|
|
57
|
+
; catch clause binding
|
|
58
|
+
(catch_clause
|
|
59
|
+
parameter: (identifier) @local.definition.var)
|
|
60
|
+
|
|
61
|
+
; -------------------------------------------------------------------------
|
|
62
|
+
; Definitions — for-in loop variables
|
|
63
|
+
;
|
|
64
|
+
; Only capture when let/const is present (kind field exists). A bare
|
|
65
|
+
; `for (k in obj)` is an assignment to an existing variable, not a new
|
|
66
|
+
; binding; tagging it as a definition would incorrectly shadow the outer `k`.
|
|
67
|
+
; -------------------------------------------------------------------------
|
|
68
|
+
|
|
69
|
+
(for_in_statement
|
|
70
|
+
kind: _
|
|
71
|
+
left: (identifier) @local.definition.var)
|
|
72
|
+
(for_in_statement
|
|
73
|
+
kind: _
|
|
74
|
+
value: (identifier) @local.definition.var)
|
|
75
|
+
(for_in_alt_statement
|
|
76
|
+
kind: _
|
|
77
|
+
left: (identifier) @local.definition.var)
|
|
78
|
+
(for_in_alt_statement
|
|
79
|
+
kind: _
|
|
80
|
+
value: (identifier) @local.definition.var)
|
|
81
|
+
|
|
82
|
+
; -------------------------------------------------------------------------
|
|
83
|
+
; Definitions — imports
|
|
84
|
+
; -------------------------------------------------------------------------
|
|
85
|
+
|
|
86
|
+
; import def from "./mod.uc"
|
|
87
|
+
(import_clause (identifier) @local.definition.import)
|
|
88
|
+
|
|
89
|
+
; import * as ns from "./mod.uc"
|
|
90
|
+
(namespace_import (identifier) @local.definition.import)
|
|
91
|
+
|
|
92
|
+
; import { a } from "./mod.uc" — name IS the local binding (no alias)
|
|
93
|
+
(import_specifier
|
|
94
|
+
name: (identifier) @local.definition.import
|
|
95
|
+
!alias)
|
|
96
|
+
|
|
97
|
+
; import { a as x } from "./mod.uc" — only the alias is the local binding
|
|
98
|
+
(import_specifier
|
|
99
|
+
alias: (identifier) @local.definition.import)
|
|
100
|
+
|
|
101
|
+
; -------------------------------------------------------------------------
|
|
102
|
+
; References
|
|
103
|
+
; -------------------------------------------------------------------------
|
|
104
|
+
|
|
105
|
+
(identifier) @local.reference
|
package/queries/tags.scm
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
; Tags queries for ucode.
|
|
2
|
+
; Used by GitHub code navigation and tools that index symbol definitions.
|
|
3
|
+
|
|
4
|
+
; -------------------------------------------------------------------------
|
|
5
|
+
; Function definitions — named declarations (brace body or endfunction body)
|
|
6
|
+
; -------------------------------------------------------------------------
|
|
7
|
+
|
|
8
|
+
(
|
|
9
|
+
(comment)* @doc
|
|
10
|
+
.
|
|
11
|
+
(function_declaration
|
|
12
|
+
name: (identifier) @name) @definition.function
|
|
13
|
+
(#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
|
|
14
|
+
(#select-adjacent! @doc @definition.function)
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
; -------------------------------------------------------------------------
|
|
18
|
+
; Function definitions — forward declarations: `function name;`
|
|
19
|
+
; -------------------------------------------------------------------------
|
|
20
|
+
|
|
21
|
+
(
|
|
22
|
+
(comment)* @doc
|
|
23
|
+
.
|
|
24
|
+
(function_forward_declaration
|
|
25
|
+
name: (identifier) @name) @definition.function
|
|
26
|
+
(#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
|
|
27
|
+
(#select-adjacent! @doc @definition.function)
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
; -------------------------------------------------------------------------
|
|
31
|
+
; Function definitions — named function expressions
|
|
32
|
+
; -------------------------------------------------------------------------
|
|
33
|
+
|
|
34
|
+
(
|
|
35
|
+
(comment)* @doc
|
|
36
|
+
.
|
|
37
|
+
(function_expression
|
|
38
|
+
name: (identifier) @name) @definition.function
|
|
39
|
+
(#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
|
|
40
|
+
(#select-adjacent! @doc @definition.function)
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
; -------------------------------------------------------------------------
|
|
44
|
+
; Function definitions — let/const assigned a function or arrow
|
|
45
|
+
; -------------------------------------------------------------------------
|
|
46
|
+
|
|
47
|
+
(
|
|
48
|
+
(comment)* @doc
|
|
49
|
+
.
|
|
50
|
+
(lexical_declaration
|
|
51
|
+
(variable_declarator
|
|
52
|
+
name: (identifier) @name
|
|
53
|
+
value: [(function_expression) (arrow_function)])) @definition.function
|
|
54
|
+
(#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
|
|
55
|
+
(#select-adjacent! @doc @definition.function)
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
; -------------------------------------------------------------------------
|
|
59
|
+
; Function definitions — assignment of function to variable or property
|
|
60
|
+
; -------------------------------------------------------------------------
|
|
61
|
+
|
|
62
|
+
(assignment_expression
|
|
63
|
+
left: [
|
|
64
|
+
(identifier) @name
|
|
65
|
+
(member_expression
|
|
66
|
+
property: (property_identifier) @name)
|
|
67
|
+
]
|
|
68
|
+
right: [(function_expression) (arrow_function)]) @definition.function
|
|
69
|
+
|
|
70
|
+
; -------------------------------------------------------------------------
|
|
71
|
+
; Function definitions — object method pairs { key: function() {} }
|
|
72
|
+
; -------------------------------------------------------------------------
|
|
73
|
+
|
|
74
|
+
(pair
|
|
75
|
+
key: (property_identifier) @name
|
|
76
|
+
value: [(function_expression) (arrow_function)]) @definition.function
|
|
77
|
+
|
|
78
|
+
; -------------------------------------------------------------------------
|
|
79
|
+
; Constants — exported scalar / expression values
|
|
80
|
+
; -------------------------------------------------------------------------
|
|
81
|
+
|
|
82
|
+
(export_statement
|
|
83
|
+
(lexical_declaration
|
|
84
|
+
(variable_declarator
|
|
85
|
+
name: (identifier) @name
|
|
86
|
+
value: [
|
|
87
|
+
(number) (string) (true) (false) (null)
|
|
88
|
+
(identifier) (binary_expression) (call_expression)
|
|
89
|
+
])) @definition.constant)
|
|
90
|
+
|
|
91
|
+
; -------------------------------------------------------------------------
|
|
92
|
+
; References — function calls
|
|
93
|
+
; -------------------------------------------------------------------------
|
|
94
|
+
|
|
95
|
+
(
|
|
96
|
+
(call_expression
|
|
97
|
+
function: (identifier) @name) @reference.call
|
|
98
|
+
(#not-match? @name "^(require|include|render)$")
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
(call_expression
|
|
102
|
+
function: (member_expression
|
|
103
|
+
property: (property_identifier) @name)
|
|
104
|
+
arguments: (_) @reference.call)
|