Skip to content

Commit

Permalink
Merge pull request #4 from chrhansk/feature-function-pointers
Browse files Browse the repository at this point in the history
Add support for declarations of variables of "function pointer" type
  • Loading branch information
b0o authored Nov 14, 2024
2 parents b7ca3ac + f467346 commit ef535ad
Show file tree
Hide file tree
Showing 5 changed files with 136,974 additions and 135,952 deletions.
26 changes: 16 additions & 10 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,20 @@ module.exports = grammar(Python, {
$.cvar_def,
$.cdef_type_declaration,
$.extern_block,
seq(
repeat($.storageclass),
optional(choice($.identifier, $.keyword_identifier)),
":",
$._indent,
repeat1(choice($.cvar_def, $.ctypedef_statement, $.cdef_type_declaration, $.extern_block)),
$._dedent,
),
$.cdef_definition_block,
),
),

cdef_definition_block: $ =>
seq(
repeat($.storageclass),
optional(choice($.identifier, $.keyword_identifier)),
":",
$._indent,
repeat1(choice($.cvar_def, $.ctypedef_statement, $.cdef_type_declaration, $.extern_block)),
$._dedent,
),

cvar_def: $ =>
seq(
repeat($.storageclass),
Expand Down Expand Up @@ -393,7 +396,7 @@ module.exports = grammar(Python, {
optional("complex"),
repeat($.type_qualifier),
)),
field("name", optional(choice($.identifier, $.operator_name))),
field("name", optional(choice($.identifier, $.operator_name, $.c_function_pointer_name))),
repeat($.type_qualifier),
),
seq(
Expand All @@ -403,6 +406,9 @@ module.exports = grammar(Python, {
),
),

c_function_pointer_name: $ =>
seq("(", "*", field("name", $.identifier), ")"),

// type_qualifier: '*' | '**' | '&' | type_index ('.' NAME [type_index])*
type_qualifier: $ =>
choice(
Expand Down Expand Up @@ -680,7 +686,7 @@ module.exports = grammar(Python, {
seq(
"sizeof",
"(",
$.c_type,
choice($.c_type, $.expression),
")",
),
),
Expand Down
164 changes: 103 additions & 61 deletions src/grammar.json

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

53 changes: 52 additions & 1 deletion src/node-types.json

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

Loading

0 comments on commit ef535ad

Please sign in to comment.