Skip to content

Commit

Permalink
feat: use the new reserved rules api
Browse files Browse the repository at this point in the history
  • Loading branch information
amaanq committed Nov 27, 2024
1 parent e8841a6 commit 467b8f3
Show file tree
Hide file tree
Showing 7 changed files with 106,178 additions and 79,093 deletions.
32 changes: 28 additions & 4 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,20 @@ module.exports = grammar({
$._abstract_declarator,
],

reserved: {
global: $ => [
'alignas', 'alignof', 'auto', 'break', 'case', 'const',
'constexpr', 'continue', 'default', 'do', 'else', 'enum',
'extern', $.false, 'for', 'goto', 'if', 'inline', 'long',
'nullptr', $.primitive_type, 'register', 'restrict', 'return',
'short', 'signed', 'sizeof', 'static', 'struct', 'switch',
'thread_local', $.true, 'typedef', 'union', 'unsigned',
'volatile', 'while', '_Alignas', '_Alignof', '_Atomic',
'_Generic', '_Noreturn',
],
attributes: _ => [],
},

word: $ => $.identifier,

rules: {
Expand Down Expand Up @@ -132,12 +146,12 @@ module.exports = grammar({
token.immediate(/\r?\n/),
),

preproc_def: $ => seq(
preproc_def: $ => reserved('attributes', seq(
preprocessor('define'),
field('name', $.identifier),
field('value', optional($.preproc_arg)),
token.immediate(/\r?\n/),
),
)),

preproc_function_def: $ => seq(
preprocessor('define'),
Expand Down Expand Up @@ -304,13 +318,23 @@ module.exports = grammar({
attribute_specifier: $ => seq(
choice('__attribute__', '__attribute'),
'(',
$.argument_list,
alias($._attribute_argument_list, $.argument_list),
')',
),

_attribute_argument_list: $ => seq(
'(',
commaSep(choice(
$.expression,
$.compound_statement,
alias('const', $.identifier),
)),
')',
),

attribute: $ => seq(
optional(seq(field('prefix', $.identifier), '::')),
field('name', $.identifier),
field('name', reserved('attributes', $.identifier)),
optional($.argument_list),
),

Expand Down
112 changes: 46 additions & 66 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 467b8f3

Please sign in to comment.