@willbooster/tree-sitter-c 5.0.2 → 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 +26 -50
- package/package.json +1 -1
- package/tree-sitter-c.wasm +0 -0
- package/tree-sitter.json +1 -1
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
|
-
...
|
|
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
|
-
...
|
|
1129
|
-
|
|
1130
|
-
|
|
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
|
},
|
package/package.json
CHANGED
package/tree-sitter-c.wasm
CHANGED
|
Binary file
|