Skip to content

Commit

Permalink
fix: rework typedef specifiers again
Browse files Browse the repository at this point in the history
  • Loading branch information
amaanq committed Jul 21, 2023
1 parent 262ce44 commit 4c49fc3
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ module.exports = grammar({
[$._type_specifier, $._expression_not_binary],
[$._type_specifier, $._expression_not_binary, $.macro_type_specifier],
[$._type_specifier, $.macro_type_specifier],
[$._typedef_type_specifier, $.macro_type_specifier],
[$.sized_type_specifier],
[$._type_specifier, $.sized_type_specifier],
[$.attributed_statement],
[$._declaration_modifiers, $.attributed_statement],
[$.enum_specifier],
Expand Down Expand Up @@ -242,7 +242,7 @@ module.exports = grammar({
type_definition: $ => seq(
'typedef',
repeat($.type_qualifier),
field('type', $._typedef_type_specifier),
field('type', $._type_specifier),
repeat($.type_qualifier),
commaSep1(field('declarator', $._type_declarator)),
';',
Expand Down Expand Up @@ -358,6 +358,8 @@ module.exports = grammar({
alias($.array_type_declarator, $.array_declarator),
alias($.parenthesized_type_declarator, $.parenthesized_declarator),
$._type_identifier,
alias(choice('signed', 'unsigned', 'long', 'short'), $.primitive_type),
$.primitive_type,
),

_abstract_declarator: $ => choice(
Expand Down Expand Up @@ -508,16 +510,6 @@ module.exports = grammar({
'noreturn',
),

_typedef_type_specifier: $ => choice(
$.struct_specifier,
$.union_specifier,
$.enum_specifier,
$.macro_type_specifier,
alias($._typedef_sized_type_specifier, $.sized_type_specifier),
$.primitive_type,
$._type_identifier,
),

_type_specifier: $ => choice(
$.struct_specifier,
$.union_specifier,
Expand All @@ -528,13 +520,6 @@ module.exports = grammar({
$._type_identifier,
),

_typedef_sized_type_specifier: _ => repeat1(choice(
'signed',
'unsigned',
'long',
'short',
)),

sized_type_specifier: $ => seq(
repeat1(choice(
'signed',
Expand Down Expand Up @@ -1168,7 +1153,10 @@ module.exports = grammar({
identifier: _ =>
/(\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})*/,

_type_identifier: $ => alias($.identifier, $.type_identifier),
_type_identifier: $ => alias(
$.identifier,
$.type_identifier,
),
_field_identifier: $ => alias($.identifier, $.field_identifier),
_statement_identifier: $ => alias($.identifier, $.statement_identifier),

Expand Down

0 comments on commit 4c49fc3

Please sign in to comment.