@willbooster/tree-sitter-c 25.0.0 → 27.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/grammar.js CHANGED
@@ -61,7 +61,7 @@ const BINARY_OPERATORS = [
61
61
  ];
62
62
 
63
63
  const LINE_SPLICE = /\\(?:\r\n?|\n\r?)/;
64
- const LINE_COMMENT = seq('/', repeat(LINE_SPLICE), '/', /(\\+(.|\r?\n)|[^\\\n])*/);
64
+ const LINE_COMMENT = seq('/', repeat(LINE_SPLICE), '/', repeat(choice(/[^\\\r\n]/, '\\', LINE_SPLICE)));
65
65
  const COMMENT_SPLICES = repeat(seq('\\', /[\r\n]/));
66
66
  const COMMENT_ESCAPE = seq('\\', /[^\r\n*]/);
67
67
  const BLOCK_COMMENT_STARS = seq(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-c",
3
- "version": "25.0.0",
3
+ "version": "27.0.0",
4
4
  "description": "C grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "c",
@@ -1,4 +1,4 @@
1
- // code-gauge-allow-file fileNcss 593 -- Annotation and argument scanners share lexical helpers and keyword tables.
1
+ // code-gauge-allow-file fileNcss 567 -- Annotation and argument scanners share lexical helpers and keyword tables.
2
2
  #ifndef TREE_SITTER_C_FUNCTION_MACRO_H_
3
3
  #define TREE_SITTER_C_FUNCTION_MACRO_H_
4
4
 
@@ -61,8 +61,6 @@ static bool function_macro_argument_quote(TSLexer *lexer, int32_t quote, bool ra
61
61
  static bool function_macro_argument_escape(TSLexer *lexer, MacroArgumentWord *word);
62
62
  static bool function_macro_argument_slash(TSLexer *lexer, bool allow_division);
63
63
  static bool function_macro_tail_spacing(TSLexer *lexer, bool *escaped, const PragmaTrivia *trivia);
64
- static bool function_macro_line_comment(TSLexer *lexer);
65
- static bool function_macro_block_comment(TSLexer *lexer);
66
64
  static void function_macro_argument_word(MacroArgumentWord *word, int32_t c);
67
65
 
68
66
  static bool function_macro_trailing_argument_prefix(TSLexer *lexer, const PragmaTrivia *trivia);
@@ -574,39 +572,11 @@ static bool function_macro_argument_quote(TSLexer *lexer, int32_t quote, bool ra
574
572
  static bool function_macro_argument_slash(TSLexer *lexer, bool allow_division) {
575
573
  lexer->advance(lexer, false);
576
574
  if (!scan_preproc_splices(lexer)) return allow_division;
577
- if (lexer->lookahead == '/') return function_macro_line_comment(lexer);
578
- if (lexer->lookahead == '*') return function_macro_block_comment(lexer);
575
+ if (lexer->lookahead == '/') return scan_preproc_line_comment(lexer);
576
+ if (lexer->lookahead == '*') return scan_preproc_block_comment(lexer);
579
577
  return allow_division;
580
578
  }
581
579
 
582
- static bool function_macro_line_comment(TSLexer *lexer) {
583
- lexer->advance(lexer, false);
584
- while (!lexer->eof(lexer) && lexer->lookahead != '\n' && lexer->lookahead != '\r') {
585
- if (lexer->lookahead == '\\') {
586
- do {
587
- lexer->advance(lexer, false);
588
- } while (lexer->lookahead == '\\');
589
- if (scan_preproc_newline(lexer, false)) continue;
590
- if (lexer->eof(lexer)) return false;
591
- }
592
- lexer->advance(lexer, false);
593
- }
594
- return true;
595
- }
596
-
597
- static bool function_macro_block_comment(TSLexer *lexer) {
598
- lexer->advance(lexer, false);
599
- bool star = false;
600
- while (!lexer->eof(lexer)) {
601
- int32_t c = lexer->lookahead;
602
- lexer->advance(lexer, false);
603
- if (c == '\\' && scan_preproc_newline(lexer, false)) continue;
604
- if (star && c == '/') return true;
605
- star = c == '*';
606
- }
607
- return false;
608
- }
609
-
610
580
  static void function_macro_argument_word(MacroArgumentWord *word, int32_t c) {
611
581
  bool member = preproc_word(c, word->identifier || word->number);
612
582
  bool digit = c >= '0' && c <= '9';
package/src/pragma.h CHANGED
@@ -1,4 +1,4 @@
1
- // code-gauge-allow-file fileNcss 476 -- Preprocessor tokens and pragma operators share names, spacing, and literal readers.
1
+ // code-gauge-allow-file fileNcss 484 -- Preprocessor tokens and pragma operators share names, spacing, and literal readers.
2
2
  #ifndef TREE_SITTER_C_PRAGMA_H_
3
3
  #define TREE_SITTER_C_PRAGMA_H_
4
4
 
@@ -43,6 +43,9 @@ static bool scan_macro_name_ucn(TSLexer *lexer);
43
43
 
44
44
  static bool scan_pragma_argument(TSLexer *lexer);
45
45
  static bool scan_pragma_spacing(TSLexer *lexer);
46
+ static bool scan_pragma_comment(TSLexer *lexer);
47
+ static bool scan_preproc_line_comment(TSLexer *lexer);
48
+ static bool scan_preproc_block_comment(TSLexer *lexer);
46
49
  static bool scan_pragma_spacing_with(TSLexer *lexer, const PragmaTrivia *trivia);
47
50
  static bool scan_pragma_empty(TSLexer *lexer, const PragmaTrivia *trivia);
48
51
  static bool scan_pragma_suffix_end_with(TSLexer *lexer, bool mark_end, const PragmaTrivia *trivia);
@@ -134,40 +137,44 @@ static bool scan_pragma_spacing(TSLexer *lexer) {
134
137
  lexer->advance(lexer, false);
135
138
  if (!scan_preproc_newline(lexer, false)) return false;
136
139
  } else if (lexer->lookahead == '/') {
137
- lexer->advance(lexer, false);
138
- if (lexer->lookahead == '/') {
139
- lexer->advance(lexer, false);
140
- while (!lexer->eof(lexer) && lexer->lookahead != '\n') {
141
- if (lexer->lookahead == '\\') {
142
- do {
143
- lexer->advance(lexer, false);
144
- } while (lexer->lookahead == '\\');
145
- if (lexer->lookahead == '\r') lexer->advance(lexer, false);
146
- if (lexer->eof(lexer)) return false;
147
- }
148
- lexer->advance(lexer, false);
149
- }
150
- } else if (lexer->lookahead == '*') {
151
- lexer->advance(lexer, false);
152
- bool star = false;
153
- for (;;) {
154
- if (lexer->eof(lexer)) return false;
155
- if (star && lexer->lookahead == '/') {
156
- lexer->advance(lexer, false);
157
- break;
158
- }
159
- star = lexer->lookahead == '*';
160
- lexer->advance(lexer, false);
161
- }
162
- } else {
163
- return false;
164
- }
140
+ if (!scan_pragma_comment(lexer)) return false;
165
141
  } else {
166
142
  return true;
167
143
  }
168
144
  }
169
145
  }
170
146
 
147
+ static bool scan_pragma_comment(TSLexer *lexer) {
148
+ lexer->advance(lexer, false);
149
+ if (!scan_preproc_splices(lexer)) return false;
150
+ if (lexer->lookahead == '/') return scan_preproc_line_comment(lexer);
151
+ if (lexer->lookahead == '*') return scan_preproc_block_comment(lexer);
152
+ return false;
153
+ }
154
+
155
+ static bool scan_preproc_line_comment(TSLexer *lexer) {
156
+ lexer->advance(lexer, false);
157
+ while (!lexer->eof(lexer) && lexer->lookahead != '\n' && lexer->lookahead != '\r') {
158
+ int32_t c = lexer->lookahead;
159
+ lexer->advance(lexer, false);
160
+ if (c == '\\') scan_preproc_newline(lexer, false);
161
+ }
162
+ return true;
163
+ }
164
+
165
+ static bool scan_preproc_block_comment(TSLexer *lexer) {
166
+ lexer->advance(lexer, false);
167
+ bool star = false;
168
+ while (!lexer->eof(lexer)) {
169
+ int32_t c = lexer->lookahead;
170
+ lexer->advance(lexer, false);
171
+ if (c == '\\' && scan_preproc_newline(lexer, false)) continue;
172
+ if (star && c == '/') return true;
173
+ star = c == '*';
174
+ }
175
+ return false;
176
+ }
177
+
171
178
  static PreprocArgumentMode preproc_argument_mode(bool tokens, bool directive, bool lparen) {
172
179
  if (tokens && directive && !lparen) return PREPROC_ARGUMENT_PRAGMA;
173
180
  return !tokens && directive ? PREPROC_ARGUMENT_TEXT : PREPROC_ARGUMENT_TOKENS;
Binary file
package/tree-sitter.json CHANGED
@@ -24,7 +24,7 @@
24
24
  }
25
25
  ],
26
26
  "metadata": {
27
- "version": "25.0.0",
27
+ "version": "27.0.0",
28
28
  "license": "MIT",
29
29
  "description": "C grammar for tree-sitter",
30
30
  "authors": [