@willbooster/tree-sitter-c 2.0.6 → 4.0.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
@@ -18,7 +18,7 @@ This fork fixes parsing bugs and raises conformance with the ISO C standard
18
18
  ## Usage
19
19
 
20
20
  The npm package ships `tree-sitter-c.wasm` for
21
- [@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter) version 1.1.6 or later, which runs in Node.js, Bun, browsers, and Cloudflare Workers. In Node.js and Bun, load the grammar from its path:
21
+ [@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter) version 1.3.0 or later, which runs in Node.js, Bun, browsers, and Cloudflare Workers. In Node.js and Bun, load the grammar from its path:
22
22
 
23
23
  ```js
24
24
  import { fileURLToPath } from 'node:url';
@@ -65,13 +65,12 @@ adjacency, so the parameter scanner must skip them again to reach `(`.
65
65
 
66
66
  In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-c) and on
67
67
  [willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter), the runtime this package is tested and
68
- fuzzed with (the grammar also loads in the upstream `tree-sitter` crate 0.27, whose error recovery never ends on some
69
- malformed input):
68
+ fuzzed with. Restricted switch-body statement queries require this fork’s generator and runtime together:
70
69
 
71
70
  ```toml
72
71
  [dependencies]
73
- tree-sitter = { package = "willbooster-tree-sitter", version = "1.1.6" }
74
- tree-sitter-c = { package = "willbooster-tree-sitter-c", version = "2" }
72
+ tree-sitter = { package = "willbooster-tree-sitter", version = "1.3.0" }
73
+ tree-sitter-c = { package = "willbooster-tree-sitter-c", version = "4" }
75
74
  ```
76
75
 
77
76
  ```rust
@@ -97,6 +96,13 @@ not the ones this package ships with. Its first run downloads that CLI from the
97
96
  with `cargo` (whose build runs the CMake that `mise.toml` pins) when the download fails or the release has no binary that runs here. Run other CLI commands through it as
98
97
  well (e.g. `script/tree-sitter parse file.c`).
99
98
 
99
+ `bun run generate` records a fresh ABI 16 generation profile from the applicable `test/corpus` cases and Git-tracked
100
+ files in `examples/`, then generates compact parser tables. The parser also embeds metadata from `tree-sitter.json`. After changing a grammar,
101
+ `tree-sitter.json`, a corpus case, or a tracked example,
102
+ regenerate and commit `src/`. Stage added or removed examples with `git add -A examples` before generation so the profile uses the intended file list.
103
+ Profiles in `.tmp/generation-profiles/` are temporary and must not be committed. `bun run build-wasm`, `bun run build/ci`,
104
+ and the release build regenerate the parsers before compiling them.
105
+
100
106
  `bun run test` runs:
101
107
 
102
108
  - the corpus in `test/corpus`, with the native build and with the Wasm build (the first run downloads the WASI SDK);
package/grammar.js CHANGED
@@ -110,6 +110,7 @@ module.exports = Object.assign(
110
110
  supertypes: ($) => [
111
111
  $.expression,
112
112
  $.statement,
113
+ $._single_noncompound_statement,
113
114
  $.type_specifier,
114
115
  $._declarator,
115
116
  $._field_declarator,
@@ -906,9 +907,10 @@ module.exports = Object.assign(
906
907
  switch_statement: ($) =>
907
908
  seq('switch', field('condition', $.parenthesized_expression), field('body', $._single_statement)),
908
909
 
909
- _single_statement: ($) =>
910
+ _single_statement: ($) => choice($.compound_statement, alias($._single_noncompound_statement, $.statement)),
911
+
912
+ _single_noncompound_statement: ($) =>
910
913
  choice(
911
- $.compound_statement,
912
914
  $.expression_statement,
913
915
  $.switch_statement,
914
916
  $.return_statement,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-c",
3
- "version": "2.0.6",
3
+ "version": "4.0.0",
4
4
  "description": "C grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -26,10 +26,11 @@
26
26
  "src/scanner.c"
27
27
  ],
28
28
  "scripts": {
29
- "build-wasm": "script/tree-sitter build --wasm",
30
- "build/ci": "script/tree-sitter generate && bun script/generateIdentifierRanges.js && script/tree-sitter build --wasm",
29
+ "build-wasm": "script/generate --build-wasm",
30
+ "build/ci": "bun run build-wasm",
31
31
  "cleanup": "bun wb lint --fix --format",
32
32
  "format": "bun wb lint --format",
33
+ "generate": "script/generate",
33
34
  "lint": "bun wb lint",
34
35
  "lint-fix": "bun wb lint --fix",
35
36
  "prepare": "(bun lefthook install || true) && (test ! -f .lefthook/normalize-bun-lockfile.sh || bash .lefthook/normalize-bun-lockfile.sh)",
@@ -50,7 +51,7 @@
50
51
  "@willbooster/oxfmt-config": "1.2.2",
51
52
  "@willbooster/oxlint-config": "1.4.8",
52
53
  "@willbooster/wb": "22.13.2",
53
- "@willbooster/web-tree-sitter": "1.1.6",
54
+ "@willbooster/web-tree-sitter": "1.4.0",
54
55
  "conventional-changelog-conventionalcommits": "10.4.0",
55
56
  "lefthook": "2.1.14",
56
57
  "oxfmt": "0.70.0",
@@ -64,7 +65,7 @@
64
65
  "wrangler": "4.136.1"
65
66
  },
66
67
  "peerDependencies": {
67
- "@willbooster/web-tree-sitter": "^1.1.6"
68
+ "@willbooster/web-tree-sitter": "^1.3.0"
68
69
  },
69
70
  "peerDependenciesMeta": {
70
71
  "@willbooster/web-tree-sitter": {
@@ -1023,54 +1023,10 @@
1023
1023
  "multiple": true,
1024
1024
  "required": false,
1025
1025
  "types": [
1026
- {
1027
- "type": "attributed_statement",
1028
- "named": true
1029
- },
1030
- {
1031
- "type": "break_statement",
1032
- "named": true
1033
- },
1034
- {
1035
- "type": "case_statement",
1036
- "named": true
1037
- },
1038
- {
1039
- "type": "compound_statement",
1040
- "named": true
1041
- },
1042
- {
1043
- "type": "continue_statement",
1044
- "named": true
1045
- },
1046
1026
  {
1047
1027
  "type": "declaration",
1048
1028
  "named": true
1049
1029
  },
1050
- {
1051
- "type": "do_statement",
1052
- "named": true
1053
- },
1054
- {
1055
- "type": "expression_statement",
1056
- "named": true
1057
- },
1058
- {
1059
- "type": "for_statement",
1060
- "named": true
1061
- },
1062
- {
1063
- "type": "goto_statement",
1064
- "named": true
1065
- },
1066
- {
1067
- "type": "if_statement",
1068
- "named": true
1069
- },
1070
- {
1071
- "type": "labeled_statement",
1072
- "named": true
1073
- },
1074
1030
  {
1075
1031
  "type": "preproc_if",
1076
1032
  "named": true
@@ -1080,28 +1036,12 @@
1080
1036
  "named": true
1081
1037
  },
1082
1038
  {
1083
- "type": "return_statement",
1084
- "named": true
1085
- },
1086
- {
1087
- "type": "seh_leave_statement",
1088
- "named": true
1089
- },
1090
- {
1091
- "type": "seh_try_statement",
1092
- "named": true
1093
- },
1094
- {
1095
- "type": "switch_statement",
1039
+ "type": "statement",
1096
1040
  "named": true
1097
1041
  },
1098
1042
  {
1099
1043
  "type": "type_definition",
1100
1044
  "named": true
1101
- },
1102
- {
1103
- "type": "while_statement",
1104
- "named": true
1105
1045
  }
1106
1046
  ]
1107
1047
  }
@@ -3893,67 +3833,7 @@
3893
3833
  "required": true,
3894
3834
  "types": [
3895
3835
  {
3896
- "type": "attributed_statement",
3897
- "named": true
3898
- },
3899
- {
3900
- "type": "break_statement",
3901
- "named": true
3902
- },
3903
- {
3904
- "type": "case_statement",
3905
- "named": true
3906
- },
3907
- {
3908
- "type": "compound_statement",
3909
- "named": true
3910
- },
3911
- {
3912
- "type": "continue_statement",
3913
- "named": true
3914
- },
3915
- {
3916
- "type": "do_statement",
3917
- "named": true
3918
- },
3919
- {
3920
- "type": "expression_statement",
3921
- "named": true
3922
- },
3923
- {
3924
- "type": "for_statement",
3925
- "named": true
3926
- },
3927
- {
3928
- "type": "goto_statement",
3929
- "named": true
3930
- },
3931
- {
3932
- "type": "if_statement",
3933
- "named": true
3934
- },
3935
- {
3936
- "type": "labeled_statement",
3937
- "named": true
3938
- },
3939
- {
3940
- "type": "return_statement",
3941
- "named": true
3942
- },
3943
- {
3944
- "type": "seh_leave_statement",
3945
- "named": true
3946
- },
3947
- {
3948
- "type": "seh_try_statement",
3949
- "named": true
3950
- },
3951
- {
3952
- "type": "switch_statement",
3953
- "named": true
3954
- },
3955
- {
3956
- "type": "while_statement",
3836
+ "type": "statement",
3957
3837
  "named": true
3958
3838
  }
3959
3839
  ]
Binary file
package/tree-sitter.json CHANGED
@@ -16,7 +16,7 @@
16
16
  }
17
17
  ],
18
18
  "metadata": {
19
- "version": "2.0.6",
19
+ "version": "4.0.0",
20
20
  "license": "MIT",
21
21
  "description": "C grammar for tree-sitter",
22
22
  "authors": [