Skip to content

Commit

Permalink
fix: allow function definitions to contain preproc attributes
Browse files Browse the repository at this point in the history
Specifically for Neovim which contains code like:

```c
Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Arena *arena, Error *err)
  FUNC_API_SINCE(8) FUNC_API_FAST
{
  ...
}
```
  • Loading branch information
lewis6991 committed Feb 13, 2024
1 parent ecdd500 commit abbb158
Show file tree
Hide file tree
Showing 5 changed files with 83,792 additions and 79,312 deletions.
35 changes: 30 additions & 5 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ module.exports = grammar({
[$.enum_specifier],
[$._type_specifier, $._old_style_parameter_list],
[$.parameter_list, $._old_style_parameter_list],
[$.function_declarator, $._function_declaration_declarator],
],

word: $ => $.identifier,
Expand Down Expand Up @@ -244,13 +245,15 @@ module.exports = grammar({

declaration: $ => seq(
$._declaration_specifiers,
$._declaration_declarator,
commaSep1(field('declarator', choice(
seq(
$._declaration_declarator,
optional($.gnu_asm_expression),
),
$.init_declarator,
))),
';',
),
_declaration_declarator: $ => commaSep1(field('declarator', choice(
seq($._declarator, optional($.gnu_asm_expression)),
$.init_declarator,
))),

type_definition: $ => seq(
optional('__extension__'),
Expand Down Expand Up @@ -357,6 +360,15 @@ module.exports = grammar({
$.identifier,
),

_declaration_declarator: $ => choice(
$.attributed_declarator,
$.pointer_declarator,
alias($._function_declaration_declarator, $.function_declarator),
$.array_declarator,
$.parenthesized_declarator,
$.identifier,
),

_field_declarator: $ => choice(
alias($.attributed_field_declarator, $.attributed_declarator),
alias($.pointer_field_declarator, $.pointer_declarator),
Expand Down Expand Up @@ -446,12 +458,25 @@ module.exports = grammar({
))),

function_declarator: $ => prec.right(1,
seq(
field('declarator', $._declarator),
field('parameters', $.parameter_list),
optional($.gnu_asm_expression),
repeat(choice(
$.attribute_specifier,
$.identifier,
$.preproc_call_expression,
)),
)),

_function_declaration_declarator: $ => prec.right(1,
seq(
field('declarator', $._declarator),
field('parameters', $.parameter_list),
optional($.gnu_asm_expression),
repeat($.attribute_specifier),
)),

function_field_declarator: $ => prec(1, seq(
field('declarator', $._field_declarator),
field('parameters', $.parameter_list),
Expand Down
223 changes: 157 additions & 66 deletions src/grammar.json

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

Loading

0 comments on commit abbb158

Please sign in to comment.