@willbooster/tree-sitter-c 5.0.1 → 5.0.3

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
@@ -35,6 +35,28 @@ const PREC = {
35
35
  SUBSCRIPT: 17,
36
36
  };
37
37
 
38
+ /** @type {[string, number][]} */
39
+ const BINARY_OPERATORS = [
40
+ ['+', PREC.ADD],
41
+ ['-', PREC.ADD],
42
+ ['*', PREC.MULTIPLY],
43
+ ['/', PREC.MULTIPLY],
44
+ ['%', PREC.MULTIPLY],
45
+ ['||', PREC.LOGICAL_OR],
46
+ ['&&', PREC.LOGICAL_AND],
47
+ ['|', PREC.INCLUSIVE_OR],
48
+ ['^', PREC.EXCLUSIVE_OR],
49
+ ['&', PREC.BITWISE_AND],
50
+ ['==', PREC.EQUAL],
51
+ ['!=', PREC.EQUAL],
52
+ ['>', PREC.RELATIONAL],
53
+ ['>=', PREC.RELATIONAL],
54
+ ['<=', PREC.RELATIONAL],
55
+ ['<', PREC.RELATIONAL],
56
+ ['<<', PREC.SHIFT],
57
+ ['>>', PREC.SHIFT],
58
+ ];
59
+
38
60
  const LINE_COMMENT = seq('//', /(\\+(.|\r?\n)|[^\\\n])*/);
39
61
  const PRAGMA_SPACING = repeat(choice(/\s/, /\\(?:\r\n?|\n\r?)/));
40
62
  const PREPROC_ARGUMENT = /\S([^/\n]|\/[^*]|\\\r?\n)*/;
@@ -268,30 +290,8 @@ module.exports = Object.assign(
268
290
  seq('(', commaSep(choice($._preproc_expression, $.system_lib_string, $.string_literal)), ')'),
269
291
 
270
292
  preproc_binary_expression: ($) => {
271
- /** @type {[string, number][]} */
272
- const table = [
273
- ['+', PREC.ADD],
274
- ['-', PREC.ADD],
275
- ['*', PREC.MULTIPLY],
276
- ['/', PREC.MULTIPLY],
277
- ['%', PREC.MULTIPLY],
278
- ['||', PREC.LOGICAL_OR],
279
- ['&&', PREC.LOGICAL_AND],
280
- ['|', PREC.INCLUSIVE_OR],
281
- ['^', PREC.EXCLUSIVE_OR],
282
- ['&', PREC.BITWISE_AND],
283
- ['==', PREC.EQUAL],
284
- ['!=', PREC.EQUAL],
285
- ['>', PREC.RELATIONAL],
286
- ['>=', PREC.RELATIONAL],
287
- ['<=', PREC.RELATIONAL],
288
- ['<', PREC.RELATIONAL],
289
- ['<<', PREC.SHIFT],
290
- ['>>', PREC.SHIFT],
291
- ];
292
-
293
293
  return choice(
294
- ...table.map(([operator, precedence]) => {
294
+ ...BINARY_OPERATORS.map(([operator, precedence]) => {
295
295
  return prec.left(
296
296
  precedence,
297
297
  seq(
@@ -1102,34 +1102,10 @@ module.exports = Object.assign(
1102
1102
  prec.left(PREC.UNARY, seq(field('operator', choice('!', '~', '-', '+')), field('argument', $.expression))),
1103
1103
 
1104
1104
  binary_expression: ($) => {
1105
- /** @type {[string, number][]} */
1106
- const table = [
1107
- ['+', PREC.ADD],
1108
- ['-', PREC.ADD],
1109
- ['*', PREC.MULTIPLY],
1110
- ['/', PREC.MULTIPLY],
1111
- ['%', PREC.MULTIPLY],
1112
- ['||', PREC.LOGICAL_OR],
1113
- ['&&', PREC.LOGICAL_AND],
1114
- ['|', PREC.INCLUSIVE_OR],
1115
- ['^', PREC.EXCLUSIVE_OR],
1116
- ['&', PREC.BITWISE_AND],
1117
- ['==', PREC.EQUAL],
1118
- ['!=', PREC.EQUAL],
1119
- ['>', PREC.RELATIONAL],
1120
- ['>=', PREC.RELATIONAL],
1121
- ['<=', PREC.RELATIONAL],
1122
- ['<', PREC.RELATIONAL],
1123
- ['<<', PREC.SHIFT],
1124
- ['>>', PREC.SHIFT],
1125
- ];
1126
-
1127
1105
  return choice(
1128
- ...table.map(([operator, precedence]) => {
1129
- return prec.left(
1130
- precedence,
1131
- seq(field('left', $.expression), field('operator', operator), field('right', $.expression))
1132
- );
1106
+ ...BINARY_OPERATORS.map(([operator, precedence]) => {
1107
+ const body = seq(field('left', $.expression), field('operator', operator), field('right', $.expression));
1108
+ return prec.left(precedence, operator === '&&' ? prec.dynamic(1, body) : body);
1133
1109
  })
1134
1110
  );
1135
1111
  },
@@ -1363,13 +1339,13 @@ module.exports = Object.assign(
1363
1339
  return token(
1364
1340
  seq(
1365
1341
  optional(/[-+]/),
1366
- optional(choice(/0[xX]/, /0[bB]/)),
1367
1342
  choice(
1368
1343
  seq(
1369
1344
  choice(decimalDigits, seq(/0[bB]/, decimalDigits), seq(/0[xX]/, hexDigits)),
1370
1345
  optional(seq('.', optional(hexDigits)))
1371
1346
  ),
1372
- seq('.', decimalDigits)
1347
+ seq('.', decimalDigits),
1348
+ seq(/0[xX]/, '.', hexDigits)
1373
1349
  ),
1374
1350
  optional(seq(/[eEpP]/, optional(seq(optional(/[-+]/), hexDigits)))),
1375
1351
  /[uUlLwWfFbBdD]*/
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-c",
3
- "version": "5.0.1",
3
+ "version": "5.0.3",
4
4
  "description": "C grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
Binary file
package/tree-sitter.json CHANGED
@@ -16,7 +16,7 @@
16
16
  }
17
17
  ],
18
18
  "metadata": {
19
- "version": "5.0.1",
19
+ "version": "5.0.3",
20
20
  "license": "MIT",
21
21
  "description": "C grammar for tree-sitter",
22
22
  "authors": [