Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,17 @@ jobs:
repository: tree-sitter/tree-sitter-c
path: node_modules/tree-sitter-c
sparse-checkout: queries/
ref: v0.23.6
ref: v0.24.1
- name: Set up tree-sitter
uses: tree-sitter/setup-action/cli@v2
- name: Run tests
uses: tree-sitter/parser-test-action@v3
with:
test-rust: true
test-node: true
# test-node: true
test-python: true
test-go: true
test-swift: true
abi-version: 14
- name: Parse examples
uses: tree-sitter/parse-action@v4
with:
Expand Down
5 changes: 3 additions & 2 deletions Cargo.toml

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

46 changes: 19 additions & 27 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ const ASSIGNMENT_OPERATORS = [
'xor_eq',
];

const commaSep = C.commaSep;
const commaSep1 = C.commaSep1;
const preprocIf = C.preprocIf;

module.exports = grammar(C, {
name: 'cpp',

Expand Down Expand Up @@ -133,8 +137,12 @@ module.exports = grammar(C, {
alias($.operator_cast_definition, $.function_definition),
alias($.operator_cast_declaration, $.declaration),
),

_block_item: ($, original) => choice(
...original.members.filter((member) => member.content?.name != '_old_style_function_definition'),
...original.members.filter((member) =>
member.content?.name != '_old_style_function_definition' &&
!member.name.startsWith('preproc_if'),
),
$.namespace_definition,
$.concept_definition,
$.namespace_alias_definition,
Expand All @@ -144,11 +152,18 @@ module.exports = grammar(C, {
$.consteval_block_declaration,
$.template_declaration,
$.template_instantiation,
$.export_declaration,
$.import_declaration,
alias($.preproc_if_in_block, $.preproc_if),
alias($.preproc_ifdef_in_block, $.preproc_ifdef),
alias($.constructor_or_destructor_definition, $.function_definition),
alias($.operator_cast_definition, $.function_definition),
alias($.operator_cast_declaration, $.declaration),
),

...preprocIf('', $ => $._top_level_item),
...preprocIf('_in_block', $ => $._block_item),

// Types

placeholder_type_specifier: $ => prec(1, seq(
Expand Down Expand Up @@ -371,13 +386,12 @@ module.exports = grammar(C, {
';',
),

export_declaration: $ => seq(
export_declaration: $ => prec(1, seq(
'export',
choice($._block_item, seq('{', repeat($._block_item), '}')),
),
choice($._block_item, $.declaration_list),
)),

import_declaration: $ => seq(
optional('export'),
'import',
choice(
field('name', $.module_name),
Expand Down Expand Up @@ -1587,25 +1601,3 @@ module.exports = grammar(C, {
_namespace_identifier: $ => alias($.identifier, $.namespace_identifier),
},
});

/**
* Creates a rule to optionally match one or more of the rules separated by a comma
*
* @param {Rule} rule
*
* @returns {ChoiceRule}
*/
function commaSep(rule) {
return optional(commaSep1(rule));
}

/**
* Creates a rule to match one or more of the rules separated by a comma
*
* @param {Rule} rule
*
* @returns {SeqRule}
*/
function commaSep1(rule) {
return seq(rule, repeat(seq(',', rule)));
}
33 changes: 10 additions & 23 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
Loading