@willbooster/tree-sitter-c 18.3.0 → 20.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 15.0.0 or later within 15.x, which runs in Node.js, Bun, browsers, and Cloudflare Workers. The parser carries the ABI number of the WillBooster/tree-sitter generator (`0x5742000b`), so it loads only with that runtime; upstream tree-sitter runtimes reject it. 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 15.0.3 or later within 15.x, which runs in Node.js, Bun, browsers, and Cloudflare Workers. The parser carries the ABI number of the WillBooster/tree-sitter generator (`0x5742000b`), so it loads only with that runtime; upstream tree-sitter runtimes reject it. In Node.js and Bun, load the grammar from its path:
22
22
 
23
23
  ```js
24
24
  import { fileURLToPath } from 'node:url';
@@ -59,23 +59,57 @@ parser.setLanguage(await Language.load(c));
59
59
 
60
60
  The package also ships `grammar.js`, scanner sources under `src/`, the queries in `queries/`,
61
61
  and the node types in `src/node-types.json` for grammars extending C (such as C++).
62
- The scanner sources include `scanner.c`, `pragma.h`, `identifier.h`, `keywords.h`, `functionMacro.h`, and
63
- `conditionalMacro.h`.
62
+ The scanner sources include `scanner.c`, `pragma.h`, `identifier.h`, `keywords.h`, `functionMacro.h`,
63
+ `conditionalMacro.h`, and `gnuRawString.h`.
64
64
 
65
65
  Derived grammars must port the inherited external-token dispatch from `src/scanner.c`.
66
66
  Keep preprocessor argument/newline handling ahead of annotation lookahead.
67
+ Port `preproc_argument_mode` selection together with `scan_preproc_arg` so tokenized pragmas retain raw bodies.
68
+ Append `_gnu_raw_string_body` and `_raw_macro_type_tail` in their inherited enum slots and port their dispatch from `src/scanner.c`.
69
+ A derived grammar overriding `raw_string_literal` can keep its own body scanner, but must retain the inherited enum slots.
67
70
  Port `_conditional_marker_ifdef`, `_conditional_marker_ifndef`, `_leading_conditional_marker_ifdef`, and
68
71
  `_leading_conditional_marker_ifndef` with `scan_conditional_macro`. The leading pair checks a following type prefix;
69
72
  when both contexts are valid, choose the leading role if its type proof succeeds, otherwise use the valid
70
73
  post-type role. Each token consumes only its opening directive keyword; the directive body, closing directive and following prefix are lookahead. Keep this dispatch ahead of
71
74
  the function-annotation guards and return immediately after a failed directive scan.
72
- The hidden `_function_attribute_start`, `_post_type_function_attribute_start`, and
73
- `_post_type_function_attribute_suffix` guards look ahead before the ordinary identifier token;
74
- keep them outside the name field so identifier leaves and ordinary C lexing retain their shape.
75
+ The hidden `_function_attribute_start`, `_post_type_function_attribute_start`,
76
+ `_post_type_function_attribute_suffix`, and `_braced_function_attribute_start` guards look ahead before the ordinary
77
+ identifier token. Keep them outside the name field so identifier leaves and ordinary C lexing retain their shape.
75
78
  Port `scan_function_attribute_guard`, its `MacroAttributeSymbols` context, and the name-range handling in `pragma.h`.
79
+ Set `braced_start` to the inherited braced token and `allow_braced_start` from its valid-symbol entry.
80
+ Omitting these fields disables braced handoff in the current argument group and in prototype-tail lookahead.
81
+ Preserve the inherited external-token order before adding tokens specific to the derived grammar.
82
+
83
+ Port `_braced_macro_type_start` and `scan_braced_macro_type_start` before function-annotation lookahead.
84
+ This separate zero-width guard proves marker words followed by a braced macro-type argument; the grammar still
85
+ consumes each marker and validates its type. Keep `MacroName.preserve_end` in `pragma.h` so scanning subsequent words
86
+ does not move the guard's end. Its default is false for ordinary name scans. Derived grammars can supply reserved
87
+ starter words and the same `MacroAttributeSymbols` context to the guard helper; the C scanner supplies an empty table.
88
+ The helper shares pragma and scalar-object dispatch with annotation guards. Copy both `functionMacro.h` and `pragma.h`
89
+ when porting this dispatch. Later pragma lookahead must preserve the zero-width token end.
90
+
91
+ When overriding declarations or function definitions, retain both guarded ordinary-type/declarator alternatives and
92
+ annotation alternatives in ordinary, block, and for-declaration builders. Accept the matching passive guard after calling conventions and before ordinary, builtin,
93
+ and initialized declarators. Derived custom declaration builders also need `_guarded_type_specifiers` and
94
+ `_marked_macro_type_specifiers`; adapt their conflicts alongside these productions. Recognized GNU and C23 attributes
95
+ also anchor the guarded type route. Retain that route in custom block and for-declaration builders. Keep the marked-type rule's
96
+ ordinary type and annotation alternatives after the prefix guard, so typedef-return prototypes remain prototypes.
97
+ Guard-owned initialized declarators also need their `_declarator` supertype alias; accepting the syntax alone does not
98
+ preserve subtype queries. Keep ordinary initializers on their existing declarator family. Custom declaration builders
99
+ must admit `_bare_marker_initializer_declaration` where they need the published bare-name initializer preference.
100
+ If their ordinary function declarators reject C's opaque trailing identifiers, adapt that private initializer route
101
+ separately and retain its `_declarator` alias.
102
+ If a derived `type_specifier` omits C macro types, its anchored `_guarded_type_specifier` must explicitly retain them
103
+ to preserve braced macro-return function bodies. Its annotation type preguard must retain the derived grammar's
104
+ anchor policy as well, so unanchored recovery keeps the complete return prefix. These adaptations do not enable
105
+ unanchored macro types globally.
106
+ Without these adapters, braced parameters, default arguments, or direct initializers can become annotations and lose
107
+ their declaration boundaries. Copy the scanner headers from the same published C version
108
+ as the grammar, update its external-token enum, then regenerate the derived parser.
76
109
  The `_trailing_object_declaration_start` guard checks an object prefix before declaration parsing;
77
110
  `_trailing_macro_attribute_name` consumes only the annotation name and preserves its ordinary identifier leaf.
78
111
  Keep the shared first-word dispatch so a failed lookahead never falls back from an advanced lexer cursor.
112
+ When both post-type guards are valid, prefer the continuation suffix so annotation chains remain on their existing path.
79
113
  First prototype guards check the prototype tail; post-type continuation guards inspect only their own argument group.
80
114
  Regenerate Unicode and keyword tables from the derived grammar's metadata.
81
115
  The generation source is `script/generateIdentifierRanges.js` in this repository.
@@ -83,13 +117,43 @@ The primitive keyword data shared by grammar generation and object-prefix classi
83
117
  The `_preproc_function_name` token ends before splices used to determine adjacency, so the `_preproc_lparen`
84
118
  scanner must skip those splices again to reach `(`.
85
119
 
86
- Prototype annotation lookahead accepts argument/prototype groups without unquoted braces, semicolons or preprocessing directives.
87
- Quoted punctuation remains literal content. GNU statement-expression, inline-tag, compound-literal
88
- and directive-bearing annotation arguments need a separate grammar design to keep malformed-input recovery bounded.
89
-
90
- Header annotation declarations use `_macro_modified_declaration`, `_macro_declaration_specifiers`,
120
+ Annotation lookahead hands the first unquoted brace in an argument group to the grammar instead of scanning the
121
+ whole braced body. The argument grammar handles compound literals, inline types, aggregate initializers, and GNU
122
+ statement expressions. Proved braced arguments also accept named declarations such as `register int a[sizeof(struct { int m; })]`,
123
+ including declaration specifiers and trailing GNU attributes. Their `parameter_declaration` nodes require a name and retain
124
+ public type and declarator subtype queries. Quoted punctuation and comments remain literal content. Semicolons and preprocessing directives
125
+ encountered before an unknown annotation's braced handoff reject that lookahead; directive-bearing arguments need
126
+ separate support. The marker proof balances recognized declaration-modifier groups, including inline types inside
127
+ attribute arguments, in one pass. Those recognized groups do not turn an attribute's internal brace into the following
128
+ macro type's handoff. Type-constructor operands and tagged definition bodies in a marked prefix
129
+ likewise keep their own braces.
130
+ Balanced groups followed by a later braced annotation retain their original guard, so typed annotation chains remain
131
+ annotations. Guarded macro types require a first type descriptor; additional arguments are grammar-parsed only under
132
+ the current-group braced hint. A semicolon can terminate an anchored declaration macro without consuming the next
133
+ declaration.
134
+
135
+ Bare initialized names remain ambiguous without preprocessing or name binding: `Word ATTR(struct { int m; }) value = {0};`
136
+ can declare an integer when `Word` is a typedef and `ATTR` is empty, or a structure when `Word` is empty and `ATTR`
137
+ selects its argument. For a genuinely bare prefix with an initialized first declarator, the grammar preserves the
138
+ published first type-name preference, even though the remaining declarator can be approximate. Uninitialized marked
139
+ types and prefixes with recognized declaration attributes or known specifiers keep the concrete macro-type route.
140
+ This preference preserves query fields; it does not resolve both macro expansions semantically.
141
+
142
+ A proved braced macro call can also supply a declarator. Its `function_declarator` keeps the macro name in `declarator`
143
+ and the structural argument group in `parameters`, so a physical semicolon, comma, initializer or function body
144
+ terminates that role without absorbing the next declaration or statement. Retain this guarded alternative and its
145
+ `_declarator` supertype alias in custom declaration-item and function-definition builders. Derived grammars with
146
+ constructor syntax keep their ordinary constructor preference; use guarded macro-call initializer/body alternatives
147
+ where that ordinary route cannot complete. The call ends at its argument group; a following identifier still needs
148
+ the annotation alternative. Normal and old-style GNU nested
149
+ function definitions retain the same guarded/marked type and annotation alternatives as top-level definitions. Macro calls and
150
+ marked function headers remain structural; they do not resolve preprocessing or name bindings.
151
+
152
+ Annotation declarations use `_macro_modified_declaration`, `_macro_declaration_specifiers`,
91
153
  `_macro_declaration_declarator`, and `_header_preproc_item`. Adapt these rules alongside public declaration/type
92
- overrides when extending C. The annotation declarator uses `function_declarator` to retain trailing macro calls.
154
+ overrides when extending C. Keep `_macro_only_declaration` as a complete semicolon-terminated item in header, block and for-declaration contexts. Allow
155
+ `_macro_declaration_specifiers` in function definitions so their bodies stay attached. The annotation declarator uses
156
+ `function_declarator` to retain trailing macro calls.
93
157
  The separate `_trailing_macro_modified_declaration` route uses public declaration specifiers and
94
158
  `_trailing_macro_object_declarator` / `_trailing_macro_pointer_declarator`; adapt these header rules when
95
159
  overriding declaration or declarator behavior.
@@ -112,19 +176,19 @@ modifier groups need separate annotation support.
112
176
 
113
177
  Trailing object annotations support one complete `primitive_type` token, plain pointer stars and an identifier,
114
178
  for example `int *value ATTR((1));`. The first argument token after initial parentheses must be numeric,
115
- a string/character quote or a comma. Comments and whitespace may separate the prefix tokens; the remaining
179
+ a string/character quote, a GNU raw-string encoding prefix or a comma. Comments and whitespace may separate the prefix tokens; the remaining
116
180
  arguments use the structural annotation-argument grammar. Sized-only starts such as `unsigned` or `long`,
117
181
  qualified/multiword/unknown-type prefixes,
118
182
  arrays, parenthesized/function declarators, initializers and multiple declarators need separate support.
119
183
 
120
184
  In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-c) and on
121
185
  [willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter), the runtime this package is tested and
122
- fuzzed with, at version 15.0.0 or later within 15.x. No other runtime loads the parser:
186
+ fuzzed with, at version 15.0.3 or later within 15.x. No other runtime loads the parser:
123
187
 
124
188
  ```toml
125
189
  [dependencies]
126
- tree-sitter = { package = "willbooster-tree-sitter", version = "15.0.0" }
127
- tree-sitter-c = { package = "willbooster-tree-sitter-c", version = "18" }
190
+ tree-sitter = { package = "willbooster-tree-sitter", version = "15.0.3" }
191
+ tree-sitter-c = { package = "willbooster-tree-sitter-c", version = "20" }
128
192
  ```
129
193
 
130
194
  ```rust