tree-sitter-ucode 0.1.2 → 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
@@ -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',
@@ -99,7 +100,6 @@ module.exports = grammar({
99
100
  ['member', 'call', $.expression],
100
101
  ['declaration', 'literal'],
101
102
  [$.primary_expression, $.statement_block, 'object'],
102
- [$.import_statement, $.import],
103
103
  [$.export_statement, $.primary_expression],
104
104
  [$.lexical_declaration, $.primary_expression],
105
105
  ],
@@ -143,7 +143,7 @@ module.exports = grammar({
143
143
  'default',
144
144
  seq(
145
145
  field('value', $.expression),
146
- $._semicolon,
146
+ ';',
147
147
  ),
148
148
  ),
149
149
  ),
@@ -173,18 +173,14 @@ module.exports = grammar({
173
173
 
174
174
  declaration: $ => choice(
175
175
  $.function_declaration,
176
- $.function_forward_declaration,
177
176
  $.lexical_declaration,
178
177
  ),
179
178
 
180
179
  //
181
180
  // Import declarations
182
181
  // Ucode keeps full ES module static import syntax.
183
- // Also adds dynamic `import(path)` as a unary expression (see import_expression).
184
182
  //
185
183
 
186
- import: _ => token('import'),
187
-
188
184
  import_statement: $ => seq(
189
185
  'import',
190
186
  choice(
@@ -461,7 +457,6 @@ module.exports = grammar({
461
457
  $.binary_expression,
462
458
  $.ternary_expression,
463
459
  $.update_expression,
464
- $.import_expression,
465
460
  ),
466
461
 
467
462
  primary_expression: $ => choice(
@@ -485,14 +480,6 @@ module.exports = grammar({
485
480
  $.call_expression,
486
481
  ),
487
482
 
488
- // Dynamic import expression: `let m = import("./mod.uc")`
489
- import_expression: $ => prec('call', seq(
490
- $.import,
491
- '(',
492
- field('source', $.expression),
493
- ')',
494
- )),
495
-
496
483
  object: $ => prec('object', seq(
497
484
  '{',
498
485
  commaSep(optional(choice(
@@ -662,13 +649,6 @@ module.exports = grammar({
662
649
  optional($._automatic_semicolon),
663
650
  )),
664
651
 
665
- // Forward declaration: `function name;`
666
- function_forward_declaration: $ => seq(
667
- 'function',
668
- field('name', $.identifier),
669
- ';',
670
- ),
671
-
672
652
  arrow_function: $ => seq(
673
653
  choice(
674
654
  field('parameter', choice(
@@ -857,7 +837,6 @@ module.exports = grammar({
857
837
  _reserved_identifier: _ => choice(
858
838
  'get',
859
839
  'set',
860
- 'let',
861
840
  ),
862
841
 
863
842
  _semicolon: $ => choice($._automatic_semicolon, ';'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tree-sitter-ucode",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "Ucode grammar for tree-sitter",
5
5
  "repository": {
6
6
  "type": "git",
@@ -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
  ; -------------------------------------------------------------------------
package/src/grammar.json CHANGED
@@ -88,8 +88,8 @@
88
88
  }
89
89
  },
90
90
  {
91
- "type": "SYMBOL",
92
- "name": "_semicolon"
91
+ "type": "STRING",
92
+ "value": ";"
93
93
  }
94
94
  ]
95
95
  }
@@ -221,23 +221,12 @@
221
221
  "type": "SYMBOL",
222
222
  "name": "function_declaration"
223
223
  },
224
- {
225
- "type": "SYMBOL",
226
- "name": "function_forward_declaration"
227
- },
228
224
  {
229
225
  "type": "SYMBOL",
230
226
  "name": "lexical_declaration"
231
227
  }
232
228
  ]
233
229
  },
234
- "import": {
235
- "type": "TOKEN",
236
- "content": {
237
- "type": "STRING",
238
- "value": "import"
239
- }
240
- },
241
230
  "import_statement": {
242
231
  "type": "SEQ",
243
232
  "members": [
@@ -1690,10 +1679,6 @@
1690
1679
  {
1691
1680
  "type": "SYMBOL",
1692
1681
  "name": "update_expression"
1693
- },
1694
- {
1695
- "type": "SYMBOL",
1696
- "name": "import_expression"
1697
1682
  }
1698
1683
  ]
1699
1684
  },
@@ -1779,35 +1764,6 @@
1779
1764
  }
1780
1765
  ]
1781
1766
  },
1782
- "import_expression": {
1783
- "type": "PREC",
1784
- "value": "call",
1785
- "content": {
1786
- "type": "SEQ",
1787
- "members": [
1788
- {
1789
- "type": "SYMBOL",
1790
- "name": "import"
1791
- },
1792
- {
1793
- "type": "STRING",
1794
- "value": "("
1795
- },
1796
- {
1797
- "type": "FIELD",
1798
- "name": "source",
1799
- "content": {
1800
- "type": "SYMBOL",
1801
- "name": "expression"
1802
- }
1803
- },
1804
- {
1805
- "type": "STRING",
1806
- "value": ")"
1807
- }
1808
- ]
1809
- }
1810
- },
1811
1767
  "object": {
1812
1768
  "type": "PREC",
1813
1769
  "value": "object",
@@ -3472,27 +3428,6 @@
3472
3428
  ]
3473
3429
  }
3474
3430
  },
3475
- "function_forward_declaration": {
3476
- "type": "SEQ",
3477
- "members": [
3478
- {
3479
- "type": "STRING",
3480
- "value": "function"
3481
- },
3482
- {
3483
- "type": "FIELD",
3484
- "name": "name",
3485
- "content": {
3486
- "type": "SYMBOL",
3487
- "name": "identifier"
3488
- }
3489
- },
3490
- {
3491
- "type": "STRING",
3492
- "value": ";"
3493
- }
3494
- ]
3495
- },
3496
3431
  "arrow_function": {
3497
3432
  "type": "SEQ",
3498
3433
  "members": [
@@ -4666,10 +4601,6 @@
4666
4601
  {
4667
4602
  "type": "STRING",
4668
4603
  "value": "set"
4669
- },
4670
- {
4671
- "type": "STRING",
4672
- "value": "let"
4673
4604
  }
4674
4605
  ]
4675
4606
  },
@@ -4842,16 +4773,6 @@
4842
4773
  "value": "object"
4843
4774
  }
4844
4775
  ],
4845
- [
4846
- {
4847
- "type": "SYMBOL",
4848
- "name": "import_statement"
4849
- },
4850
- {
4851
- "type": "SYMBOL",
4852
- "name": "import"
4853
- }
4854
- ],
4855
4776
  [
4856
4777
  {
4857
4778
  "type": "SYMBOL",
@@ -4984,6 +4905,10 @@
4984
4905
  "type": "STRING",
4985
4906
  "value": "in"
4986
4907
  },
4908
+ {
4909
+ "type": "STRING",
4910
+ "value": "let"
4911
+ },
4987
4912
  {
4988
4913
  "type": "STRING",
4989
4914
  "value": "null"
@@ -7,10 +7,6 @@
7
7
  "type": "function_declaration",
8
8
  "named": true
9
9
  },
10
- {
11
- "type": "function_forward_declaration",
12
- "named": true
13
- },
14
10
  {
15
11
  "type": "lexical_declaration",
16
12
  "named": true
@@ -33,10 +29,6 @@
33
29
  "type": "binary_expression",
34
30
  "named": true
35
31
  },
36
- {
37
- "type": "import_expression",
38
- "named": true
39
- },
40
32
  {
41
33
  "type": "primary_expression",
42
34
  "named": true
@@ -1229,22 +1221,6 @@
1229
1221
  }
1230
1222
  }
1231
1223
  },
1232
- {
1233
- "type": "function_forward_declaration",
1234
- "named": true,
1235
- "fields": {
1236
- "name": {
1237
- "multiple": false,
1238
- "required": true,
1239
- "types": [
1240
- {
1241
- "type": "identifier",
1242
- "named": true
1243
- }
1244
- ]
1245
- }
1246
- }
1247
- },
1248
1224
  {
1249
1225
  "type": "if_alt_statement",
1250
1226
  "named": true,
@@ -1327,11 +1303,6 @@
1327
1303
  }
1328
1304
  }
1329
1305
  },
1330
- {
1331
- "type": "import",
1332
- "named": true,
1333
- "fields": {}
1334
- },
1335
1306
  {
1336
1307
  "type": "import_clause",
1337
1308
  "named": true,
@@ -1355,32 +1326,6 @@
1355
1326
  ]
1356
1327
  }
1357
1328
  },
1358
- {
1359
- "type": "import_expression",
1360
- "named": true,
1361
- "fields": {
1362
- "source": {
1363
- "multiple": false,
1364
- "required": true,
1365
- "types": [
1366
- {
1367
- "type": "expression",
1368
- "named": true
1369
- }
1370
- ]
1371
- }
1372
- },
1373
- "children": {
1374
- "multiple": false,
1375
- "required": true,
1376
- "types": [
1377
- {
1378
- "type": "import",
1379
- "named": true
1380
- }
1381
- ]
1382
- }
1383
- },
1384
1329
  {
1385
1330
  "type": "import_specifier",
1386
1331
  "named": true,