@willbooster/tree-sitter-c 1.4.1 → 1.5.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
@@ -37,6 +37,7 @@ const PREC = {
37
37
 
38
38
  const LINE_COMMENT = seq('//', /(\\+(.|\r?\n)|[^\\\n])*/);
39
39
  const PRAGMA_SPACING = repeat(choice(/\s/, /\\\r?\n/));
40
+ const VA_ARG_KEYWORDS = choice('va_arg', '__builtin_va_arg');
40
41
 
41
42
  // oxlint-disable-next-line unicorn/prefer-module -- This package is CommonJS, so tree-sitter loads grammar.js as CommonJS.
42
43
  module.exports = Object.assign(
@@ -44,6 +45,12 @@ module.exports = Object.assign(
44
45
  name: 'c',
45
46
 
46
47
  conflicts: ($) => [
48
+ [$.type_specifier, $.expression, $.va_arg_expression, $.macro_type_specifier],
49
+ [$.va_arg_expression, $.expression],
50
+ [$.type_definition, $._declaration_modifiers],
51
+ [$.type_definition, $.type_specifier],
52
+ [$.type_definition, $.type_qualifier, $.extension_expression],
53
+ [$.type_definition, $.type_qualifier],
47
54
  [$._declaration_modifiers, $._empty_declaration],
48
55
  [$.declaration, $.storage_class_specifier],
49
56
  [$.sized_type_specifier, $.enum_specifier],
@@ -57,6 +64,11 @@ module.exports = Object.assign(
57
64
  [$.sized_type_specifier],
58
65
  [$._sized_bit_int_specifier],
59
66
  [$.sized_type_specifier, $._sized_bit_int_specifier],
67
+ [$._type_declarator, $.sized_type_specifier, $._sized_bit_int_specifier],
68
+ [$.type_qualifier, $.atomic_type_specifier],
69
+ [$.type_definition, $._type_declarator],
70
+ [$.type_definition, $.sized_type_specifier],
71
+ [$.type_definition, $._sized_bit_int_specifier],
60
72
  [$.attributed_statement],
61
73
  [$._declaration_modifiers, $.attributed_statement],
62
74
  [$.enum_specifier],
@@ -77,6 +89,7 @@ module.exports = Object.assign(
77
89
  extras: ($) => [$.pragma_operator, /\s|\\\r?\n/, $.comment],
78
90
 
79
91
  inline: ($) => [
92
+ $._non_identifier_type_specifier,
80
93
  $._type_identifier,
81
94
  $._field_identifier,
82
95
  $._statement_identifier,
@@ -323,9 +336,17 @@ module.exports = Object.assign(
323
336
 
324
337
  type_definition: ($) =>
325
338
  seq(
326
- optional('__extension__'),
327
- 'typedef',
328
- $._type_definition_type,
339
+ optional(prec.dynamic(1, '__extension__')),
340
+ choice(
341
+ seq(repeat($.type_qualifier), 'typedef', $._type_definition_type),
342
+ seq(
343
+ repeat($._declaration_modifiers),
344
+ field('type', $._non_identifier_type_specifier),
345
+ repeat($.type_qualifier),
346
+ 'typedef',
347
+ repeat(choice($.type_qualifier, $._non_identifier_type_specifier))
348
+ )
349
+ ),
329
350
  $._type_definition_declarators,
330
351
  repeat($.attribute_specifier),
331
352
  ';'
@@ -396,7 +417,8 @@ module.exports = Object.assign(
396
417
  $.function_declarator,
397
418
  $.array_declarator,
398
419
  $.parenthesized_declarator,
399
- $.identifier
420
+ $.identifier,
421
+ alias(VA_ARG_KEYWORDS, $.identifier)
400
422
  ),
401
423
 
402
424
  _declaration_declarator: ($) =>
@@ -406,7 +428,8 @@ module.exports = Object.assign(
406
428
  alias($._function_declaration_declarator, $.function_declarator),
407
429
  $.array_declarator,
408
430
  $.parenthesized_declarator,
409
- $.identifier
431
+ $.identifier,
432
+ alias(VA_ARG_KEYWORDS, $.identifier)
410
433
  ),
411
434
 
412
435
  _field_declarator: ($) =>
@@ -626,18 +649,24 @@ module.exports = Object.assign(
626
649
  alignas_qualifier: ($) => seq(choice('alignas', '_Alignas'), '(', choice($.expression, $.type_descriptor), ')'),
627
650
 
628
651
  type_specifier: ($) =>
652
+ choice(
653
+ $._non_identifier_type_specifier,
654
+ $.macro_type_specifier,
655
+ $._type_identifier,
656
+ prec.dynamic(-1, alias('thread_local', sym('type_identifier')))
657
+ ),
658
+
659
+ _non_identifier_type_specifier: ($) =>
629
660
  choice(
630
661
  $.struct_specifier,
631
662
  $.union_specifier,
632
663
  $.enum_specifier,
633
664
  $.typeof_specifier,
634
665
  $.bit_int_specifier,
635
- $.macro_type_specifier,
666
+ $.atomic_type_specifier,
636
667
  $.sized_type_specifier,
637
668
  alias($._sized_bit_int_specifier, $.sized_type_specifier),
638
- $.primitive_type,
639
- $._type_identifier,
640
- prec.dynamic(-1, alias('thread_local', sym('type_identifier')))
669
+ $.primitive_type
641
670
  ),
642
671
 
643
672
  typeof_specifier: ($) =>
@@ -647,6 +676,8 @@ module.exports = Object.assign(
647
676
  choice($.type_descriptor, $.expression, $.comma_expression),
648
677
  ')'
649
678
  ),
679
+ atomic_type_specifier: ($) => seq('_Atomic', '(', field('type', $.type_descriptor), ')'),
680
+
650
681
  bit_int_specifier: ($) => seq('_BitInt', '(', $.expression, ')'),
651
682
 
652
683
  sized_type_specifier: ($) =>
@@ -786,7 +817,8 @@ module.exports = Object.assign(
786
817
 
787
818
  parameter_list: ($) =>
788
819
  seq('(', choice(commaSep(choice($.parameter_declaration, $.variadic_parameter)), $.compound_statement), ')'),
789
- _old_style_parameter_list: ($) => seq('(', commaSep(choice($.identifier, $.variadic_parameter)), ')'),
820
+ _old_style_parameter_list: ($) =>
821
+ seq('(', commaSep(choice($.identifier, alias(VA_ARG_KEYWORDS, $.identifier), $.variadic_parameter)), ')'),
790
822
 
791
823
  parameter_declaration: ($) =>
792
824
  seq(
@@ -930,6 +962,7 @@ module.exports = Object.assign(
930
962
  $.sizeof_expression,
931
963
  $.alignof_expression,
932
964
  $.offsetof_expression,
965
+ $.va_arg_expression,
933
966
  $.generic_expression,
934
967
  $.subscript_expression,
935
968
  $.call_expression,
@@ -937,6 +970,7 @@ module.exports = Object.assign(
937
970
  $.compound_literal_expression,
938
971
  $.identifier,
939
972
  alias('thread_local', $.identifier),
973
+ alias(VA_ARG_KEYWORDS, $.identifier),
940
974
  $.number_literal,
941
975
  $._string,
942
976
  $.true,
@@ -968,6 +1002,7 @@ module.exports = Object.assign(
968
1002
 
969
1003
  _assignment_left_expression: ($) =>
970
1004
  choice(
1005
+ alias(VA_ARG_KEYWORDS, $.identifier),
971
1006
  $.identifier,
972
1007
  $.call_expression,
973
1008
  $.field_expression,
@@ -1043,17 +1078,23 @@ module.exports = Object.assign(
1043
1078
  ),
1044
1079
 
1045
1080
  sizeof_expression: ($) =>
1046
- prec(
1047
- PREC.SIZEOF,
1048
- seq('sizeof', choice(field('value', $.expression), seq('(', field('type', $.type_descriptor), ')')))
1081
+ prec.dynamic(
1082
+ 2,
1083
+ prec(
1084
+ PREC.SIZEOF,
1085
+ seq('sizeof', choice(field('value', $.expression), seq('(', field('type', $.type_descriptor), ')')))
1086
+ )
1049
1087
  ),
1050
1088
 
1051
1089
  alignof_expression: ($) =>
1052
- prec(
1053
- PREC.SIZEOF,
1054
- seq(
1055
- choice('__alignof__', '__alignof', '_alignof', 'alignof', '_Alignof'),
1056
- seq('(', field('type', $.type_descriptor), ')')
1090
+ prec.dynamic(
1091
+ 2,
1092
+ prec(
1093
+ PREC.SIZEOF,
1094
+ seq(
1095
+ choice('__alignof__', '__alignof', '_alignof', 'alignof', '_Alignof'),
1096
+ seq('(', field('type', $.type_descriptor), ')')
1097
+ )
1057
1098
  )
1058
1099
  ),
1059
1100
 
@@ -1063,6 +1104,12 @@ module.exports = Object.assign(
1063
1104
  seq('offsetof', seq('(', field('type', $.type_descriptor), ',', field('member', $._field_identifier), ')'))
1064
1105
  ),
1065
1106
 
1107
+ va_arg_expression: ($) =>
1108
+ prec.dynamic(
1109
+ 1,
1110
+ seq(VA_ARG_KEYWORDS, '(', field('value', $.expression), ',', field('type', $.type_descriptor), ')')
1111
+ ),
1112
+
1066
1113
  generic_expression: ($) =>
1067
1114
  prec(
1068
1115
  PREC.CALL,
@@ -1313,14 +1360,22 @@ module.exports = Object.assign(
1313
1360
  identifier: () =>
1314
1361
  /(\p{XID_Start}|\$|_|\\u[0-9A-Fa-f]{4}|\\U[0-9A-Fa-f]{8})(\p{XID_Continue}|\$|\\u[0-9A-Fa-f]{4}|\\U[0-9A-Fa-f]{8})*/u,
1315
1362
 
1316
- _type_identifier: ($) => alias($.identifier, sym('type_identifier')),
1317
- _field_identifier: ($) => alias($.identifier, sym('field_identifier')),
1318
- _statement_identifier: ($) => alias($.identifier, sym('statement_identifier')),
1363
+ _type_identifier: ($) => alias(choice($.identifier, VA_ARG_KEYWORDS), sym('type_identifier')),
1364
+ _field_identifier: ($) => alias(choice($.identifier, VA_ARG_KEYWORDS), sym('field_identifier')),
1365
+ _statement_identifier: ($) => alias(choice($.identifier, VA_ARG_KEYWORDS), sym('statement_identifier')),
1319
1366
 
1320
1367
  _empty_declaration: ($) => seq(repeat($.ms_declspec_modifier), $.type_specifier, ';'),
1321
1368
 
1322
1369
  macro_type_specifier: ($) =>
1323
- prec.dynamic(-1, seq(field('name', $.identifier), '(', field('type', $.type_descriptor), ')')),
1370
+ prec.dynamic(
1371
+ -1,
1372
+ seq(
1373
+ field('name', choice($.identifier, alias(VA_ARG_KEYWORDS, $.identifier))),
1374
+ '(',
1375
+ field('type', $.type_descriptor),
1376
+ ')'
1377
+ )
1378
+ ),
1324
1379
 
1325
1380
  // http://stackoverflow.com/questions/13014947/regex-to-match-a-c-style-multiline-comment/36328890#36328890
1326
1381
  comment: () => token(choice(LINE_COMMENT, seq('/*', /[^*]*\*+([^/*][^*]*\*+)*/, '/'))),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-c",
3
- "version": "1.4.1",
3
+ "version": "1.5.0",
4
4
  "description": "C grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -87,3 +87,5 @@
87
87
  ["typeof" "typeof_unqual" "__typeof__" "__typeof" "__typeof_unqual" "__typeof_unqual__"] @keyword)
88
88
  (bit_int_specifier "_BitInt" @type)
89
89
  (pragma_operator) @keyword
90
+
91
+ (va_arg_expression ["va_arg" "__builtin_va_arg"] @keyword)
@@ -226,6 +226,10 @@
226
226
  {
227
227
  "type": "update_expression",
228
228
  "named": true
229
+ },
230
+ {
231
+ "type": "va_arg_expression",
232
+ "named": true
229
233
  }
230
234
  ]
231
235
  },
@@ -303,6 +307,10 @@
303
307
  "type": "type_specifier",
304
308
  "named": true,
305
309
  "subtypes": [
310
+ {
311
+ "type": "atomic_type_specifier",
312
+ "named": true
313
+ },
306
314
  {
307
315
  "type": "bit_int_specifier",
308
316
  "named": true
@@ -670,6 +678,22 @@
670
678
  }
671
679
  }
672
680
  },
681
+ {
682
+ "type": "atomic_type_specifier",
683
+ "named": true,
684
+ "fields": {
685
+ "type": {
686
+ "multiple": false,
687
+ "required": true,
688
+ "types": [
689
+ {
690
+ "type": "type_descriptor",
691
+ "named": true
692
+ }
693
+ ]
694
+ }
695
+ }
696
+ },
673
697
  {
674
698
  "type": "attribute",
675
699
  "named": true,
@@ -4019,13 +4043,57 @@
4019
4043
  "multiple": true,
4020
4044
  "required": false,
4021
4045
  "types": [
4046
+ {
4047
+ "type": "atomic_type_specifier",
4048
+ "named": true
4049
+ },
4050
+ {
4051
+ "type": "attribute_declaration",
4052
+ "named": true
4053
+ },
4022
4054
  {
4023
4055
  "type": "attribute_specifier",
4024
4056
  "named": true
4025
4057
  },
4058
+ {
4059
+ "type": "bit_int_specifier",
4060
+ "named": true
4061
+ },
4062
+ {
4063
+ "type": "enum_specifier",
4064
+ "named": true
4065
+ },
4066
+ {
4067
+ "type": "ms_declspec_modifier",
4068
+ "named": true
4069
+ },
4070
+ {
4071
+ "type": "primitive_type",
4072
+ "named": true
4073
+ },
4074
+ {
4075
+ "type": "sized_type_specifier",
4076
+ "named": true
4077
+ },
4078
+ {
4079
+ "type": "storage_class_specifier",
4080
+ "named": true
4081
+ },
4082
+ {
4083
+ "type": "struct_specifier",
4084
+ "named": true
4085
+ },
4026
4086
  {
4027
4087
  "type": "type_qualifier",
4028
4088
  "named": true
4089
+ },
4090
+ {
4091
+ "type": "typeof_specifier",
4092
+ "named": true
4093
+ },
4094
+ {
4095
+ "type": "union_specifier",
4096
+ "named": true
4029
4097
  }
4030
4098
  ]
4031
4099
  }
@@ -4216,6 +4284,32 @@
4216
4284
  }
4217
4285
  }
4218
4286
  },
4287
+ {
4288
+ "type": "va_arg_expression",
4289
+ "named": true,
4290
+ "fields": {
4291
+ "type": {
4292
+ "multiple": false,
4293
+ "required": true,
4294
+ "types": [
4295
+ {
4296
+ "type": "type_descriptor",
4297
+ "named": true
4298
+ }
4299
+ ]
4300
+ },
4301
+ "value": {
4302
+ "multiple": false,
4303
+ "required": true,
4304
+ "types": [
4305
+ {
4306
+ "type": "expression",
4307
+ "named": true
4308
+ }
4309
+ ]
4310
+ }
4311
+ }
4312
+ },
4219
4313
  {
4220
4314
  "type": "variadic_parameter",
4221
4315
  "named": true,
@@ -4563,6 +4657,10 @@
4563
4657
  "type": "__builtin_available",
4564
4658
  "named": false
4565
4659
  },
4660
+ {
4661
+ "type": "__builtin_va_arg",
4662
+ "named": false
4663
+ },
4566
4664
  {
4567
4665
  "type": "__cdecl",
4568
4666
  "named": false
@@ -4921,6 +5019,10 @@
4921
5019
  "type": "unsigned",
4922
5020
  "named": false
4923
5021
  },
5022
+ {
5023
+ "type": "va_arg",
5024
+ "named": false
5025
+ },
4924
5026
  {
4925
5027
  "type": "version_number",
4926
5028
  "named": true
Binary file
package/tree-sitter.json CHANGED
@@ -16,7 +16,7 @@
16
16
  }
17
17
  ],
18
18
  "metadata": {
19
- "version": "1.4.1",
19
+ "version": "1.5.0",
20
20
  "license": "MIT",
21
21
  "description": "C grammar for tree-sitter",
22
22
  "authors": [