Skip to content

Commit

Permalink
Support Macro-Based Structure Augmentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Reshetnikov committed Jun 6, 2024
1 parent 715560a commit 1d84f26
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 9 deletions.
24 changes: 20 additions & 4 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,9 @@ module.exports = grammar({
...preprocIf('_in_enumerator_list', $ => seq($.enumerator, ',')),
...preprocIf('_in_enumerator_list_no_comma', $ => $.enumerator, -1),


preproc_arg: $ => prec(-1,
preproc_arg: $ => prec(-1,
seq(token(/\\\r?\n|\S/), repeat(choice($.comment, token(/[^/\n]|\/[^*]|\\\r?\n/))))
),
),

preproc_directive: _ => /#[ \t]*[a-zA-Z0-9]\w*/,

Expand Down Expand Up @@ -244,12 +243,14 @@ module.exports = grammar({
optional($.ms_call_modifier),
$._declaration_specifiers,
optional($.ms_call_modifier),
optional($.macro_modifier),
field('declarator', $._declarator),
field('body', $.compound_statement),
),

_old_style_function_definition: $ => seq(
optional($.ms_call_modifier),
optional($.macro_modifier),
$._declaration_specifiers,
field('declarator', alias($._old_style_function_declarator, $.function_declarator)),
repeat($.declaration),
Expand All @@ -261,6 +262,7 @@ module.exports = grammar({
commaSep1(field('declarator', choice(
seq(
optional($.ms_call_modifier),
optional($.macro_modifier),
$._declaration_declarator,
optional($.gnu_asm_expression),
),
Expand Down Expand Up @@ -311,7 +313,6 @@ module.exports = grammar({
'__read_mostly',
seq(choice('__must_hold'), '(', $.argument_list, ')'),
'__ro_after_init',
'__init'
),
),

Expand Down Expand Up @@ -339,6 +340,11 @@ module.exports = grammar({
$.argument_list,
),

macro_modifier: _ => choice(
'__init',
'__exit',
),

ms_call_modifier: _ => choice(
'__cdecl',
'__clrcall',
Expand Down Expand Up @@ -417,24 +423,28 @@ module.exports = grammar({
parenthesized_declarator: $ => prec.dynamic(PREC.PAREN_DECLARATOR, seq(
'(',
optional($.ms_call_modifier),
optional($.macro_modifier),
$._declarator,
')',
)),
parenthesized_field_declarator: $ => prec.dynamic(PREC.PAREN_DECLARATOR, seq(
'(',
optional($.ms_call_modifier),
optional($.macro_modifier),
$._field_declarator,
')',
)),
parenthesized_type_declarator: $ => prec.dynamic(PREC.PAREN_DECLARATOR, seq(
'(',
optional($.ms_call_modifier),
optional($.macro_modifier),
$._type_declarator,
')',
)),
abstract_parenthesized_declarator: $ => prec(1, seq(
'(',
optional($.ms_call_modifier),
optional($.macro_modifier),
$._abstract_declarator,
')',
)),
Expand Down Expand Up @@ -735,6 +745,12 @@ module.exports = grammar({
$.preproc_call,
alias($.preproc_if_in_field_declaration_list, $.preproc_if),
alias($.preproc_ifdef_in_field_declaration_list, $.preproc_ifdef),
$.macro_invocation,
),

macro_invocation: $ => seq(
field('declarator', $._declarator),
field('parameters', $.parameter_list),
),

field_declaration: $ => seq(
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

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

24 changes: 19 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@
"name": "tree-sitter-c",
"version": "0.21.4",
"description": "C grammar for tree-sitter",
"repository": "github:tree-sitter/tree-sitter-c",
"repository": {
"type": "git",
"url": "git+https://github.com/tree-sitter/tree-sitter-c.git"
},
"license": "MIT",
"author": "Max Brunsfeld <[email protected]>",
"contributors": [
"Amaan Qureshi <[email protected]>"
{
"name": "Amaan Qureshi",
"email": "[email protected]"
}
],
"main": "bindings/node",
"types": "bindings/node",
Expand All @@ -25,8 +31,8 @@
"src/**"
],
"dependencies": {
"node-addon-api": "^8.0.0",
"node-gyp-build": "^4.8.1"
"node-gyp-build": "^4.8.1",
"node-addon-api": "^7.1.0"
},
"peerDependencies": {
"tree-sitter": "^0.21.0"
Expand Down Expand Up @@ -104,5 +110,13 @@
}
]
}
}
},
"directories": {
"example": "examples",
"test": "test"
},
"bugs": {
"url": "https://github.com/tree-sitter/tree-sitter-c/issues"
},
"homepage": "https://github.com/tree-sitter/tree-sitter-c#readme"
}
75 changes: 75 additions & 0 deletions src/node-types.json

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

0 comments on commit 1d84f26

Please sign in to comment.