tree-sitter-ucode 0.1.0 → 0.2.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/README.md CHANGED
@@ -17,13 +17,12 @@ Ucode is an ECMAScript subset with OpenWrt-specific extensions. Key differences:
17
17
  |---------|-------|------------|
18
18
  | Alternative block syntax | `if/elif/else/endif`, `for/endfor`, `while/endwhile`, `function/endfunction` | Not supported |
19
19
  | Two-variable for-in | `for (k, v in obj)` | Single variable only |
20
- | Forward declaration | `function foo;` | Not supported |
21
- | Removed keywords | `var`, `new`, `typeof`, `void`, `class`, `instanceof`, `do`, `async`, `await`, `yield` | All supported |
22
- | Removed features | Destructuring, `for...of`, `do-while`, generators | All supported |
20
+ | Removed keywords | `var`, `new`, `throw`, `typeof`, `void`, `class`, `instanceof`, `do`, `async`, `await`, `yield` | All supported |
21
+ | Removed features | Destructuring, `for...of`, `do-while`, generators, forward declarations, dynamic `import()` | All supported |
23
22
  | Added number literals | `0177` (C octal), `0x1.8` (hex float), `0B`/`0O` prefixes | Standard only |
24
23
  | Added escape sequences | `\e` (ESC), `\a` (BEL), octal `\177` | Standard only |
25
24
  | Regex flags | `g`, `i`, `s` only | Full set |
26
- | Module system | Static `import`/`export`, dynamic `import(path)`; no `from` on re-exports | Full ES modules |
25
+ | Module system | Static `import`/`export` only; no `from` on re-exports | Full ES modules |
27
26
 
28
27
  ## Requirements
29
28
 
package/grammar.js CHANGED
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * Based on tree-sitter-javascript (MIT, Max Brunsfeld, Amaan Qureshi).
6
6
  * Ucode is an ECMAScript-like language for OpenWrt system scripting.
7
- * See linter/diff-to-js.md for a full list of syntax differences from JS.
7
+ * See README.md for a full list of syntax differences from JavaScript.
8
8
  */
9
9
 
10
10
  /// <reference types="tree-sitter-cli/dsl" />
@@ -46,6 +46,7 @@ module.exports = grammar({
46
46
  'if',
47
47
  'import',
48
48
  'in',
49
+ 'let',
49
50
  'null',
50
51
  'return',
51
52
  'switch',
@@ -54,7 +55,7 @@ module.exports = grammar({
54
55
  'try',
55
56
  'while',
56
57
  ],
57
- properties: $ => [],
58
+ properties: _ => [],
58
59
  },
59
60
 
60
61
  supertypes: $ => [
@@ -84,7 +85,6 @@ module.exports = grammar({
84
85
  'binary_times',
85
86
  'binary_plus',
86
87
  'binary_shift',
87
- 'binary_compare',
88
88
  'binary_relation',
89
89
  'binary_equality',
90
90
  'bitwise_and',
@@ -100,22 +100,16 @@ module.exports = grammar({
100
100
  ['member', 'call', $.expression],
101
101
  ['declaration', 'literal'],
102
102
  [$.primary_expression, $.statement_block, 'object'],
103
- [$.import_statement, $.import],
104
103
  [$.export_statement, $.primary_expression],
105
104
  [$.lexical_declaration, $.primary_expression],
106
105
  ],
107
106
 
108
107
  conflicts: $ => [
109
- [$.primary_expression, $._property_name],
110
- [$.primary_expression, $.arrow_function],
111
- [$.primary_expression, $.arrow_function, $._property_name],
112
108
  [$.primary_expression, $.formal_parameters],
113
109
  [$.primary_expression, $._for_header],
114
110
  [$.variable_declarator, $._for_header],
115
111
  [$.assignment_expression, $.pattern],
116
112
  [$.labeled_statement, $._property_name],
117
- [$.computed_property_name, $.array],
118
- [$.binary_expression, $._initializer],
119
113
  ],
120
114
 
121
115
  word: $ => $.identifier,
@@ -149,7 +143,7 @@ module.exports = grammar({
149
143
  'default',
150
144
  seq(
151
145
  field('value', $.expression),
152
- $._semicolon,
146
+ ';',
153
147
  ),
154
148
  ),
155
149
  ),
@@ -179,18 +173,14 @@ module.exports = grammar({
179
173
 
180
174
  declaration: $ => choice(
181
175
  $.function_declaration,
182
- $.function_forward_declaration,
183
176
  $.lexical_declaration,
184
177
  ),
185
178
 
186
179
  //
187
180
  // Import declarations
188
181
  // Ucode keeps full ES module static import syntax.
189
- // Also adds dynamic `import(path)` as a unary expression (see import_expression).
190
182
  //
191
183
 
192
- import: _ => token('import'),
193
-
194
184
  import_statement: $ => seq(
195
185
  'import',
196
186
  choice(
@@ -325,36 +315,12 @@ module.exports = grammar({
325
315
  ),
326
316
 
327
317
  for_statement: $ => seq(
328
- 'for',
329
- '(',
330
- choice(
331
- field('initializer', $.lexical_declaration),
332
- seq(field('initializer', $._expressions), ';'),
333
- field('initializer', $.empty_statement),
334
- ),
335
- field('condition', choice(
336
- seq($._expressions, ';'),
337
- $.empty_statement,
338
- )),
339
- field('increment', optional($._expressions)),
340
- ')',
318
+ forHeader($),
341
319
  field('body', $.statement),
342
320
  ),
343
321
 
344
322
  for_alt_statement: $ => seq(
345
- 'for',
346
- '(',
347
- choice(
348
- field('initializer', $.lexical_declaration),
349
- seq(field('initializer', $._expressions), ';'),
350
- field('initializer', $.empty_statement),
351
- ),
352
- field('condition', choice(
353
- seq($._expressions, ';'),
354
- $.empty_statement,
355
- )),
356
- field('increment', optional($._expressions)),
357
- ')',
323
+ forHeader($),
358
324
  ':',
359
325
  field('body', repeat($.statement)),
360
326
  'endfor',
@@ -491,7 +457,6 @@ module.exports = grammar({
491
457
  $.binary_expression,
492
458
  $.ternary_expression,
493
459
  $.update_expression,
494
- $.import_expression,
495
460
  ),
496
461
 
497
462
  primary_expression: $ => choice(
@@ -515,14 +480,6 @@ module.exports = grammar({
515
480
  $.call_expression,
516
481
  ),
517
482
 
518
- // Dynamic import expression: `let m = import("./mod.uc")`
519
- import_expression: $ => prec('call', seq(
520
- $.import,
521
- '(',
522
- field('source', $.expression),
523
- ')',
524
- )),
525
-
526
483
  object: $ => prec('object', seq(
527
484
  '{',
528
485
  commaSep(optional(choice(
@@ -680,7 +637,7 @@ module.exports = grammar({
680
637
  field('body', $.statement_block),
681
638
  )),
682
639
 
683
- // Named function declaration with brace body
640
+ // Function declaration brace body or alternative colon/endfunction syntax
684
641
  function_declaration: $ => prec.right('declaration', seq(
685
642
  'function',
686
643
  field('name', $.identifier),
@@ -692,13 +649,6 @@ module.exports = grammar({
692
649
  optional($._automatic_semicolon),
693
650
  )),
694
651
 
695
- // Forward declaration: `function name;`
696
- function_forward_declaration: $ => seq(
697
- 'function',
698
- field('name', $.identifier),
699
- ';',
700
- ),
701
-
702
652
  arrow_function: $ => seq(
703
653
  choice(
704
654
  field('parameter', choice(
@@ -765,7 +715,7 @@ module.exports = grammar({
765
715
  /x[0-9a-fA-F]{2}/,
766
716
  /u[0-9a-fA-F]{4}/,
767
717
  /u\{[0-9a-fA-F]+\}/,
768
- /[\r?][\n\u2028\u2029]/,
718
+ /\r[\n\u2028\u2029]/,
769
719
  ),
770
720
  )),
771
721
 
@@ -887,13 +837,30 @@ module.exports = grammar({
887
837
  _reserved_identifier: _ => choice(
888
838
  'get',
889
839
  'set',
890
- 'let',
891
840
  ),
892
841
 
893
842
  _semicolon: $ => choice($._automatic_semicolon, ';'),
894
843
  },
895
844
  });
896
845
 
846
+ function forHeader($) {
847
+ return seq(
848
+ 'for',
849
+ '(',
850
+ choice(
851
+ field('initializer', $.lexical_declaration),
852
+ seq(field('initializer', $._expressions), ';'),
853
+ field('initializer', $.empty_statement),
854
+ ),
855
+ field('condition', choice(
856
+ seq($._expressions, ';'),
857
+ $.empty_statement,
858
+ )),
859
+ field('increment', optional($._expressions)),
860
+ ')',
861
+ );
862
+ }
863
+
897
864
  function commaSep1(rule) {
898
865
  return seq(rule, repeat(seq(',', rule)));
899
866
  }
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "name": "tree-sitter-ucode",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Ucode grammar for tree-sitter",
5
- "repository": "https://github.com/m00qek/tree-sitter-ucode",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/m00qek/tree-sitter-ucode.git"
8
+ },
6
9
  "license": "MIT",
7
10
  "main": "bindings/node",
8
11
  "types": "bindings/node",
@@ -53,9 +53,6 @@
53
53
  (function_declaration
54
54
  name: (identifier) @function)
55
55
 
56
- (function_forward_declaration
57
- name: (identifier) @function)
58
-
59
56
  (function_expression
60
57
  name: (identifier) @function)
61
58
 
@@ -121,8 +118,6 @@
121
118
 
122
119
  ["import" "export"] @keyword.import
123
120
  ["as" "from"] @keyword.import
124
- ; Dynamic import() uses a named node, not an anonymous string
125
- (import_expression (import) @keyword.import)
126
121
 
127
122
  ; -------------------------------------------------------------------------
128
123
  ; Keywords — storage / operators
@@ -6,7 +6,6 @@
6
6
  ; -------------------------------------------------------------------------
7
7
 
8
8
  (function_declaration) @local.scope
9
- ; function_forward_declaration has no body — it is a definition, not a scope
10
9
  (function_expression) @local.scope
11
10
  (arrow_function) @local.scope
12
11
  ; statement_block provides block scoping for let/const
@@ -23,16 +22,12 @@
23
22
  ; Definitions — functions
24
23
  ; -------------------------------------------------------------------------
25
24
 
26
- ; Declaration and forward-declaration names belong to the *enclosing* scope
27
- ; so that callers outside the function body can resolve them.
25
+ ; Function declaration names belong to the enclosing scope so that
26
+ ; callers outside the function body can resolve them.
28
27
  (function_declaration
29
28
  name: (identifier) @local.definition.function
30
29
  (#set! definition.function.scope parent))
31
30
 
32
- (function_forward_declaration
33
- name: (identifier) @local.definition.function
34
- (#set! definition.function.scope parent))
35
-
36
31
  ; Named function expressions (let f = function foo() {}) keep their name
37
32
  ; *inside* the expression scope — foo is only visible for self-recursion,
38
33
  ; not to the surrounding block. No (#set! parent) here.
package/queries/tags.scm CHANGED
@@ -14,19 +14,6 @@
14
14
  (#select-adjacent! @doc @definition.function)
15
15
  )
16
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
17
  ; -------------------------------------------------------------------------
31
18
  ; Function definitions — named function expressions
32
19
  ; -------------------------------------------------------------------------