tree-sitter-ucode 0.3.0 → 0.4.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.
Files changed (43) hide show
  1. package/README.md +32 -81
  2. package/grammar.js +214 -28
  3. package/markup/grammar.js +1057 -0
  4. package/markup/queries/folds.scm +20 -0
  5. package/markup/queries/highlights.scm +38 -0
  6. package/markup/queries/indents.scm +51 -0
  7. package/markup/queries/injections.scm +40 -0
  8. package/markup/queries/locals.scm +107 -0
  9. package/markup/queries/tags.scm +65 -0
  10. package/markup/queries/textobjects.scm +56 -0
  11. package/markup/src/grammar.json +5786 -0
  12. package/markup/src/node-types.json +3211 -0
  13. package/markup/src/parser.c +134461 -0
  14. package/markup/src/scanner.c +22 -0
  15. package/package.json +6 -5
  16. package/prebuilds/darwin-arm64/tree-sitter-ucode.node +0 -0
  17. package/prebuilds/linux-arm64/tree-sitter-ucode.node +0 -0
  18. package/prebuilds/linux-x64/tree-sitter-ucode.node +0 -0
  19. package/prebuilds/win32-x64/tree-sitter-ucode.node +0 -0
  20. package/queries/locals.scm +1 -0
  21. package/scripts/generate-markup-grammar.js +93 -0
  22. package/src/grammar.json +1069 -226
  23. package/src/node-types.json +662 -8
  24. package/src/parser.c +106401 -25117
  25. package/src/scanner.c +16 -193
  26. package/src/scanner_impl.h +494 -0
  27. package/tree-sitter-ucode.wasm +0 -0
  28. package/tree-sitter-ucode_markup.wasm +0 -0
  29. package/tree-sitter.json +33 -22
  30. package/tmpl/grammar.js +0 -68
  31. package/tmpl/queries/folds.scm +0 -4
  32. package/tmpl/queries/highlights.scm +0 -23
  33. package/tmpl/queries/indents.scm +0 -5
  34. package/tmpl/queries/injections.scm +0 -8
  35. package/tmpl/queries/locals.scm +0 -3
  36. package/tmpl/src/grammar.json +0 -251
  37. package/tmpl/src/node-types.json +0 -238
  38. package/tmpl/src/parser.c +0 -724
  39. package/tmpl/src/scanner.c +0 -174
  40. package/tree-sitter-ucode_tmpl.wasm +0 -0
  41. /package/{tmpl → markup}/src/tree_sitter/alloc.h +0 -0
  42. /package/{tmpl → markup}/src/tree_sitter/array.h +0 -0
  43. /package/{tmpl → markup}/src/tree_sitter/parser.h +0 -0
@@ -0,0 +1,20 @@
1
+ ; Fold queries for ucode_markup.
2
+
3
+ ; Code-level folds — same structures appear as real AST nodes inside tags
4
+ [
5
+ (statement_block)
6
+ (switch_body)
7
+ (object)
8
+ (array)
9
+ ] @fold
10
+
11
+ ; Alt-syntax template blocks — fold the entire construct
12
+ [
13
+ (if_alt_statement)
14
+ (for_alt_statement)
15
+ (for_in_alt_statement)
16
+ (while_alt_statement)
17
+ ] @fold
18
+
19
+ ; Colon-body function declarations inside statement tags
20
+ (function_declaration "endfunction") @fold
@@ -0,0 +1,38 @@
1
+ ; Markup-mode highlights for ucode_markup grammar
2
+ ; (.uc.tmpl files)
3
+
4
+ ; ── Tag delimiters ────────────────────────────────────────────────────────────
5
+
6
+ (statement_tag_open) @punctuation.special
7
+ (statement_tag_trim_open) @punctuation.special
8
+ (statement_tag_lstrip_open) @punctuation.special
9
+ (statement_tag_close) @punctuation.special
10
+ (statement_tag_trim_close) @punctuation.special
11
+ (expression_tag_open) @punctuation.special
12
+ (expression_tag_trim_open) @punctuation.special
13
+ (expression_tag_close) @punctuation.special
14
+ (expression_tag_trim_close) @punctuation.special
15
+
16
+ ; ── Comment tags ─────────────────────────────────────────────────────────────
17
+
18
+ (comment_tag) @comment
19
+
20
+ ; ── Alt-syntax structural keywords ────────────────────────────────────────────
21
+ ;
22
+ ; These tokens appear between the tag-open external token and the close of the
23
+ ; alt header (before the : that ends the condition/header). They are not
24
+ ; injected — they are literal tokens visible in the ucode_markup parse tree.
25
+
26
+ ["if" "elif" "else" "endif"] @keyword.conditional
27
+ ["for" "endfor" "while" "endwhile"] @keyword.repeat
28
+ "in" @keyword.operator
29
+
30
+ (if_alt_statement ":" @punctuation.delimiter)
31
+ (elif_clause_tag ":" @punctuation.delimiter)
32
+ (for_alt_statement ":" @punctuation.delimiter)
33
+ (for_in_alt_statement ":" @punctuation.delimiter)
34
+ (while_alt_statement ":" @punctuation.delimiter)
35
+ (function_declaration ":" @punctuation.delimiter)
36
+
37
+ ; ── Code tokens inside statement/expression tags are highlighted via injection ─
38
+ ; (see markup/queries/injections.scm)
@@ -0,0 +1,51 @@
1
+ ; Indentation queries for ucode_markup.
2
+
3
+ ; ── Brace-delimited constructs inside statement tags ──────────────────────────
4
+
5
+ [
6
+ (statement_block)
7
+ (switch_body)
8
+ (object)
9
+ (array)
10
+ (arguments)
11
+ (formal_parameters)
12
+ ] @indent.begin
13
+
14
+ [
15
+ "}"
16
+ "]"
17
+ ")"
18
+ ] @indent.end
19
+
20
+ ; ── Alt-syntax template blocks ────────────────────────────────────────────────
21
+
22
+ (if_alt_statement ":" @indent.begin)
23
+ (elif_clause ":" @indent.begin)
24
+ (for_alt_statement ":" @indent.begin)
25
+ (for_in_alt_statement ":" @indent.begin)
26
+ (while_alt_statement ":" @indent.begin)
27
+ (function_declaration ":" @indent.begin)
28
+
29
+ [
30
+ "endif"
31
+ "endfor"
32
+ "endwhile"
33
+ "endfunction"
34
+ ] @indent.end
35
+
36
+ (else_clause "else") @indent.branch
37
+ (else_alt_clause "else") @indent.branch
38
+ (else_alt_clause_tag "else") @indent.branch
39
+ (elif_clause "elif") @indent.branch
40
+ (elif_clause_tag "elif") @indent.branch
41
+
42
+ ; else variants have no ':' so @indent.branch alone doesn't open a body scope
43
+ (else_alt_clause) @indent.begin
44
+ (else_alt_clause_tag) @indent.begin
45
+
46
+ (elif_clause_tag ":" @indent.begin)
47
+
48
+ ; ── Switch ────────────────────────────────────────────────────────────────────
49
+
50
+ (switch_case "case") @indent.branch
51
+ (switch_default "default") @indent.branch
@@ -0,0 +1,40 @@
1
+ ; Inject the ucode grammar into statement and expression tag bodies.
2
+ ;
3
+ ; The entire statement_tag (excluding open/close markers) and the expression
4
+ ; inside an expression_tag are highlighted as ucode code.
5
+
6
+ (statement_tag
7
+ ((_) @injection.content
8
+ (#not-type? @injection.content
9
+ statement_tag_open statement_tag_trim_open statement_tag_lstrip_open
10
+ statement_tag_close statement_tag_trim_close))
11
+ (#set! injection.language "ucode"))
12
+
13
+ (expression_tag
14
+ ((_) @injection.content
15
+ (#not-type? @injection.content
16
+ expression_tag_open expression_tag_trim_open
17
+ expression_tag_close expression_tag_trim_close))
18
+ (#set! injection.language "ucode"))
19
+
20
+ ; Alt-syntax header expressions.
21
+ ;
22
+ ; Conditions and loop headers live directly on the alt-syntax node, not
23
+ ; inside a statement_tag, so the captures above do not reach them. The
24
+ ; `open: (_)` guard selects the markup form of each rule (the one with tag
25
+ ; delimiters) and excludes the code form that appears inside statement_tag
26
+ ; bodies (which are already covered by the statement_tag capture above).
27
+
28
+ (if_alt_statement open: (_) condition: (_) @injection.content (#set! injection.language "ucode"))
29
+ (elif_clause_tag condition: (_) @injection.content (#set! injection.language "ucode"))
30
+ (while_alt_statement open: (_) condition: (_) @injection.content (#set! injection.language "ucode"))
31
+
32
+ (for_alt_statement open: (_) initializer: (_) @injection.content
33
+ (#not-type? @injection.content empty_statement)
34
+ (#set! injection.language "ucode"))
35
+ (for_alt_statement open: (_) condition: (_) @injection.content
36
+ (#not-type? @injection.content empty_statement)
37
+ (#set! injection.language "ucode"))
38
+ (for_alt_statement open: (_) increment: (_) @injection.content (#set! injection.language "ucode"))
39
+
40
+ (for_in_alt_statement open: (_) right: (_) @injection.content (#set! injection.language "ucode"))
@@ -0,0 +1,107 @@
1
+ ; Locals for ucode_markup.
2
+ ; The markup parser produces a single unified tree — code inside {% %} and
3
+ ; {{ }} tags is parsed as real AST nodes, not opaque code blobs. Variable
4
+ ; bindings declared in one tag are therefore visible in subsequent sibling
5
+ ; tags, and the rules below resolve that scope correctly without needing
6
+ ; injection.
7
+
8
+ ; -------------------------------------------------------------------------
9
+ ; Scopes
10
+ ; -------------------------------------------------------------------------
11
+
12
+ ; The whole document is the implicit top-level scope.
13
+ (markup) @local.scope
14
+
15
+ ; Structural scopes inside tags — same rules as the code grammar.
16
+ (function_declaration) @local.scope
17
+ (function_expression) @local.scope
18
+ (arrow_function) @local.scope
19
+ ; statement_block provides block scoping for let/const
20
+ (statement_block) @local.scope
21
+ ; for loops scope their initialiser variable(s) to the loop body
22
+ (for_statement) @local.scope
23
+ (for_alt_statement) @local.scope
24
+ (for_in_statement) @local.scope
25
+ (for_in_alt_statement) @local.scope
26
+ ; catch clause scopes its parameter to the handler body
27
+ (catch_clause) @local.scope
28
+
29
+ ; -------------------------------------------------------------------------
30
+ ; Definitions — functions
31
+ ; -------------------------------------------------------------------------
32
+
33
+ ; Function declaration names belong to the enclosing scope so that
34
+ ; callers outside the function body can resolve them.
35
+ (function_declaration
36
+ name: (identifier) @local.definition.function
37
+ (#set! definition.function.scope parent))
38
+
39
+ ; Named function expressions keep their name inside the expression scope
40
+ ; (self-recursion only).
41
+ (function_expression
42
+ name: (identifier) @local.definition.function)
43
+
44
+ ; -------------------------------------------------------------------------
45
+ ; Definitions — variables
46
+ ; -------------------------------------------------------------------------
47
+
48
+ (variable_declarator
49
+ name: (identifier) @local.definition.var)
50
+
51
+ ; -------------------------------------------------------------------------
52
+ ; Definitions — parameters
53
+ ; -------------------------------------------------------------------------
54
+
55
+ (formal_parameters (identifier) @local.definition.parameter)
56
+ (rest_element (identifier) @local.definition.parameter)
57
+ (arrow_function parameter: (identifier) @local.definition.parameter)
58
+
59
+ ; catch clause binding
60
+ (catch_clause
61
+ parameter: (identifier) @local.definition.var)
62
+
63
+ ; -------------------------------------------------------------------------
64
+ ; Definitions — for-in loop variables
65
+ ;
66
+ ; Only capture when let/const is present (kind field exists). A bare
67
+ ; `for (k in obj)` is an assignment to an existing variable, not a new
68
+ ; binding; tagging it as a definition would incorrectly shadow the outer `k`.
69
+ ; -------------------------------------------------------------------------
70
+
71
+ (for_in_statement
72
+ kind: _
73
+ left: (identifier) @local.definition.var)
74
+ (for_in_statement
75
+ kind: _
76
+ value: (identifier) @local.definition.var)
77
+ (for_in_alt_statement
78
+ kind: _
79
+ left: (identifier) @local.definition.var)
80
+ (for_in_alt_statement
81
+ kind: _
82
+ value: (identifier) @local.definition.var)
83
+
84
+ ; -------------------------------------------------------------------------
85
+ ; Definitions — imports
86
+ ; -------------------------------------------------------------------------
87
+
88
+ ; import def from "./mod.uc"
89
+ (import_clause (identifier) @local.definition.import)
90
+
91
+ ; import * as ns from "./mod.uc"
92
+ (namespace_import (identifier) @local.definition.import)
93
+
94
+ ; import { a } from "./mod.uc" — name IS the local binding (no alias)
95
+ (import_specifier
96
+ name: (identifier) @local.definition.import
97
+ !alias)
98
+
99
+ ; import { a as x } from "./mod.uc" — only the alias is the local binding
100
+ (import_specifier
101
+ alias: (identifier) @local.definition.import)
102
+
103
+ ; -------------------------------------------------------------------------
104
+ ; References
105
+ ; -------------------------------------------------------------------------
106
+
107
+ (identifier) @local.reference
@@ -0,0 +1,65 @@
1
+ ; Tags queries for ucode_markup.
2
+ ; The markup grammar produces a unified tree — function declarations and
3
+ ; other named symbols inside {% %} tags are real AST nodes, so the same
4
+ ; patterns as the code grammar apply here.
5
+
6
+ (
7
+ (comment)* @doc
8
+ .
9
+ (function_declaration
10
+ name: (identifier) @name) @definition.function
11
+ (#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
12
+ (#select-adjacent! @doc @definition.function)
13
+ )
14
+
15
+ (
16
+ (comment)* @doc
17
+ .
18
+ (function_expression
19
+ name: (identifier) @name) @definition.function
20
+ (#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
21
+ (#select-adjacent! @doc @definition.function)
22
+ )
23
+
24
+ (
25
+ (comment)* @doc
26
+ .
27
+ (lexical_declaration
28
+ (variable_declarator
29
+ name: (identifier) @name
30
+ value: [(function_expression) (arrow_function)])) @definition.function
31
+ (#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
32
+ (#select-adjacent! @doc @definition.function)
33
+ )
34
+
35
+ (assignment_expression
36
+ left: [
37
+ (identifier) @name
38
+ (member_expression
39
+ property: (property_identifier) @name)
40
+ ]
41
+ right: [(function_expression) (arrow_function)]) @definition.function
42
+
43
+ (pair
44
+ key: (property_identifier) @name
45
+ value: [(function_expression) (arrow_function)]) @definition.function
46
+
47
+ (export_statement
48
+ (lexical_declaration
49
+ (variable_declarator
50
+ name: (identifier) @name
51
+ value: [
52
+ (number) (string) (true) (false) (null)
53
+ (identifier) (binary_expression) (call_expression)
54
+ ])) @definition.constant)
55
+
56
+ (
57
+ (call_expression
58
+ function: (identifier) @name) @reference.call
59
+ (#not-match? @name "^(require|include|render)$")
60
+ )
61
+
62
+ (call_expression
63
+ function: (member_expression
64
+ property: (property_identifier) @name)
65
+ arguments: (_) @reference.call)
@@ -0,0 +1,56 @@
1
+ ; Text-object queries for ucode_markup.
2
+ ; Code nodes inside {% %} tags are real AST nodes in the unified tree,
3
+ ; so the same patterns as the code grammar apply here.
4
+
5
+ ; ── Functions ─────────────────────────────────────────────────────────────────
6
+
7
+ (function_declaration
8
+ body: (statement_block) @function.inner) @function.outer
9
+
10
+ (function_declaration "endfunction") @function.outer
11
+
12
+ (function_expression
13
+ body: (statement_block) @function.inner) @function.outer
14
+
15
+ (arrow_function
16
+ body: (statement_block) @function.inner) @function.outer
17
+
18
+ (arrow_function
19
+ body: (expression) @function.inner) @function.outer
20
+
21
+ ; ── Parameters ────────────────────────────────────────────────────────────────
22
+
23
+ (formal_parameters (_) @parameter.inner)
24
+ (formal_parameters (_) @parameter.outer)
25
+
26
+ ; ── Conditionals ──────────────────────────────────────────────────────────────
27
+
28
+ (if_statement
29
+ consequence: (statement_block) @conditional.inner) @conditional.outer
30
+
31
+ (if_alt_statement) @conditional.outer
32
+
33
+ ; ── Loops ─────────────────────────────────────────────────────────────────────
34
+
35
+ (for_statement
36
+ body: (statement_block) @loop.inner) @loop.outer
37
+
38
+ (for_in_statement
39
+ body: (statement_block) @loop.inner) @loop.outer
40
+
41
+ (while_statement
42
+ body: (statement_block) @loop.inner) @loop.outer
43
+
44
+ (for_alt_statement) @loop.outer
45
+ (for_in_alt_statement) @loop.outer
46
+ (while_alt_statement) @loop.outer
47
+
48
+ ; ── Calls ─────────────────────────────────────────────────────────────────────
49
+
50
+ (call_expression
51
+ arguments: (arguments) @call.inner) @call.outer
52
+
53
+ ; ── Blocks ────────────────────────────────────────────────────────────────────
54
+
55
+ (statement_block) @block.outer
56
+ (statement_block (_) @block.inner)