Skip to content

Commit 365ff86

Browse files
committed
feat: C23
1 parent 6180180 commit 365ff86

File tree

6 files changed

+79254
-61885
lines changed

6 files changed

+79254
-61885
lines changed

grammar.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -471,15 +471,18 @@ module.exports = grammar({
471471
'auto',
472472
'register',
473473
'inline',
474+
'thread_local',
474475
),
475476

476477
type_qualifier: _ => choice(
477478
'const',
479+
'constexpr',
478480
'volatile',
479481
'restrict',
480482
'__restrict__',
481483
'_Atomic',
482484
'_Noreturn',
485+
'noreturn',
483486
),
484487

485488
_type_specifier: $ => choice(
@@ -514,9 +517,12 @@ module.exports = grammar({
514517
'void',
515518
'size_t',
516519
'ssize_t',
520+
'ptrdiff_t',
517521
'intptr_t',
518522
'uintptr_t',
519523
'charptr_t',
524+
'nullptr_t',
525+
'max_align_t',
520526
...[8, 16, 32, 64].map(n => `int${n}_t`),
521527
...[8, 16, 32, 64].map(n => `uint${n}_t`),
522528
...[8, 16, 32, 64].map(n => `char${n}_t`),
@@ -1086,7 +1092,7 @@ module.exports = grammar({
10861092

10871093
true: _ => token(choice('TRUE', 'true')),
10881094
false: _ => token(choice('FALSE', 'false')),
1089-
null: _ => 'NULL',
1095+
null: _ => choice('NULL', 'nullptr'),
10901096

10911097
identifier: _ => /(\p{XID_Start}|_)\p{XID_Continue}*/,
10921098

@@ -1167,7 +1173,7 @@ function preprocIf(suffix, content) {
11671173
choice(preprocessor('ifdef'), preprocessor('ifndef')),
11681174
field('name', $.identifier),
11691175
repeat(content($)),
1170-
field('alternative', optional(elseBlock($))),
1176+
field('alternative', optional(choice(elseBlock($), $.preproc_elifdef))),
11711177
preprocessor('endif'),
11721178
),
11731179

@@ -1183,6 +1189,13 @@ function preprocIf(suffix, content) {
11831189
repeat(content($)),
11841190
field('alternative', optional(elseBlock($))),
11851191
),
1192+
1193+
['preproc_elifdef' + suffix]: $ => seq(
1194+
choice(preprocessor('elifdef'), preprocessor('elifndef')),
1195+
field('name', $.identifier),
1196+
repeat(content($)),
1197+
field('alternative', optional(elseBlock($))),
1198+
),
11861199
};
11871200
}
11881201

src/grammar.json

+216-19
Original file line numberDiff line numberDiff line change
@@ -424,12 +424,21 @@
424424
"type": "CHOICE",
425425
"members": [
426426
{
427-
"type": "SYMBOL",
428-
"name": "preproc_else"
427+
"type": "CHOICE",
428+
"members": [
429+
{
430+
"type": "SYMBOL",
431+
"name": "preproc_else"
432+
},
433+
{
434+
"type": "SYMBOL",
435+
"name": "preproc_elif"
436+
}
437+
]
429438
},
430439
{
431440
"type": "SYMBOL",
432-
"name": "preproc_elif"
441+
"name": "preproc_elifdef"
433442
}
434443
]
435444
},
@@ -529,6 +538,74 @@
529538
}
530539
]
531540
},
541+
"preproc_elifdef": {
542+
"type": "SEQ",
543+
"members": [
544+
{
545+
"type": "CHOICE",
546+
"members": [
547+
{
548+
"type": "ALIAS",
549+
"content": {
550+
"type": "PATTERN",
551+
"value": "#[ \t]*elifdef"
552+
},
553+
"named": false,
554+
"value": "#elifdef"
555+
},
556+
{
557+
"type": "ALIAS",
558+
"content": {
559+
"type": "PATTERN",
560+
"value": "#[ \t]*elifndef"
561+
},
562+
"named": false,
563+
"value": "#elifndef"
564+
}
565+
]
566+
},
567+
{
568+
"type": "FIELD",
569+
"name": "name",
570+
"content": {
571+
"type": "SYMBOL",
572+
"name": "identifier"
573+
}
574+
},
575+
{
576+
"type": "REPEAT",
577+
"content": {
578+
"type": "SYMBOL",
579+
"name": "_top_level_item"
580+
}
581+
},
582+
{
583+
"type": "FIELD",
584+
"name": "alternative",
585+
"content": {
586+
"type": "CHOICE",
587+
"members": [
588+
{
589+
"type": "CHOICE",
590+
"members": [
591+
{
592+
"type": "SYMBOL",
593+
"name": "preproc_else"
594+
},
595+
{
596+
"type": "SYMBOL",
597+
"name": "preproc_elif"
598+
}
599+
]
600+
},
601+
{
602+
"type": "BLANK"
603+
}
604+
]
605+
}
606+
}
607+
]
608+
},
532609
"preproc_if_in_field_declaration_list": {
533610
"type": "SEQ",
534611
"members": [
@@ -657,22 +734,31 @@
657734
"type": "CHOICE",
658735
"members": [
659736
{
660-
"type": "ALIAS",
661-
"content": {
662-
"type": "SYMBOL",
663-
"name": "preproc_else_in_field_declaration_list"
664-
},
665-
"named": true,
666-
"value": "preproc_else"
737+
"type": "CHOICE",
738+
"members": [
739+
{
740+
"type": "ALIAS",
741+
"content": {
742+
"type": "SYMBOL",
743+
"name": "preproc_else_in_field_declaration_list"
744+
},
745+
"named": true,
746+
"value": "preproc_else"
747+
},
748+
{
749+
"type": "ALIAS",
750+
"content": {
751+
"type": "SYMBOL",
752+
"name": "preproc_elif_in_field_declaration_list"
753+
},
754+
"named": true,
755+
"value": "preproc_elif"
756+
}
757+
]
667758
},
668759
{
669-
"type": "ALIAS",
670-
"content": {
671-
"type": "SYMBOL",
672-
"name": "preproc_elif_in_field_declaration_list"
673-
},
674-
"named": true,
675-
"value": "preproc_elif"
760+
"type": "SYMBOL",
761+
"name": "preproc_elifdef"
676762
}
677763
]
678764
},
@@ -782,6 +868,84 @@
782868
}
783869
]
784870
},
871+
"preproc_elifdef_in_field_declaration_list": {
872+
"type": "SEQ",
873+
"members": [
874+
{
875+
"type": "CHOICE",
876+
"members": [
877+
{
878+
"type": "ALIAS",
879+
"content": {
880+
"type": "PATTERN",
881+
"value": "#[ \t]*elifdef"
882+
},
883+
"named": false,
884+
"value": "#elifdef"
885+
},
886+
{
887+
"type": "ALIAS",
888+
"content": {
889+
"type": "PATTERN",
890+
"value": "#[ \t]*elifndef"
891+
},
892+
"named": false,
893+
"value": "#elifndef"
894+
}
895+
]
896+
},
897+
{
898+
"type": "FIELD",
899+
"name": "name",
900+
"content": {
901+
"type": "SYMBOL",
902+
"name": "identifier"
903+
}
904+
},
905+
{
906+
"type": "REPEAT",
907+
"content": {
908+
"type": "SYMBOL",
909+
"name": "_field_declaration_list_item"
910+
}
911+
},
912+
{
913+
"type": "FIELD",
914+
"name": "alternative",
915+
"content": {
916+
"type": "CHOICE",
917+
"members": [
918+
{
919+
"type": "CHOICE",
920+
"members": [
921+
{
922+
"type": "ALIAS",
923+
"content": {
924+
"type": "SYMBOL",
925+
"name": "preproc_else_in_field_declaration_list"
926+
},
927+
"named": true,
928+
"value": "preproc_else"
929+
},
930+
{
931+
"type": "ALIAS",
932+
"content": {
933+
"type": "SYMBOL",
934+
"name": "preproc_elif_in_field_declaration_list"
935+
},
936+
"named": true,
937+
"value": "preproc_elif"
938+
}
939+
]
940+
},
941+
{
942+
"type": "BLANK"
943+
}
944+
]
945+
}
946+
}
947+
]
948+
},
785949
"preproc_directive": {
786950
"type": "PATTERN",
787951
"value": "#[ \\t]*[a-zA-Z]\\w*"
@@ -3043,6 +3207,10 @@
30433207
{
30443208
"type": "STRING",
30453209
"value": "inline"
3210+
},
3211+
{
3212+
"type": "STRING",
3213+
"value": "thread_local"
30463214
}
30473215
]
30483216
},
@@ -3053,6 +3221,10 @@
30533221
"type": "STRING",
30543222
"value": "const"
30553223
},
3224+
{
3225+
"type": "STRING",
3226+
"value": "constexpr"
3227+
},
30563228
{
30573229
"type": "STRING",
30583230
"value": "volatile"
@@ -3072,6 +3244,10 @@
30723244
{
30733245
"type": "STRING",
30743246
"value": "_Noreturn"
3247+
},
3248+
{
3249+
"type": "STRING",
3250+
"value": "noreturn"
30753251
}
30763252
]
30773253
},
@@ -3203,6 +3379,10 @@
32033379
"type": "STRING",
32043380
"value": "ssize_t"
32053381
},
3382+
{
3383+
"type": "STRING",
3384+
"value": "ptrdiff_t"
3385+
},
32063386
{
32073387
"type": "STRING",
32083388
"value": "intptr_t"
@@ -3215,6 +3395,14 @@
32153395
"type": "STRING",
32163396
"value": "charptr_t"
32173397
},
3398+
{
3399+
"type": "STRING",
3400+
"value": "nullptr_t"
3401+
},
3402+
{
3403+
"type": "STRING",
3404+
"value": "max_align_t"
3405+
},
32183406
{
32193407
"type": "STRING",
32203408
"value": "int8_t"
@@ -7116,8 +7304,17 @@
71167304
}
71177305
},
71187306
"null": {
7119-
"type": "STRING",
7120-
"value": "NULL"
7307+
"type": "CHOICE",
7308+
"members": [
7309+
{
7310+
"type": "STRING",
7311+
"value": "NULL"
7312+
},
7313+
{
7314+
"type": "STRING",
7315+
"value": "nullptr"
7316+
}
7317+
]
71217318
},
71227319
"identifier": {
71237320
"type": "PATTERN",

0 commit comments

Comments
 (0)