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
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml

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

9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ and nested directives inside array bounds remain unsupported. This version
also recognizes qualified defaulted constructors, including namespace-qualified
owners and exception specifications, both at file scope and inside namespaces.

Version 0.24.3 preserves the conditional guard around declarations that follow
the closing brace of split language-linkage blocks. Headers can combine an
unconditional C declaration with C++ overloads inside the closing
`__cplusplus` guard without parser recovery changing their scope.

Generation uses the pinned C grammar 0.24.1 and Tree-sitter CLI 0.26.3.
The 0.23.x line remains based on upstream 0.23.4 with parser ABI 14.

Expand All @@ -41,14 +46,14 @@ The 0.23.x line remains based on upstream 0.23.4 with parser ABI 14.
Add the Brokk-maintained Rust crate to your project:

```sh
cargo add brokk-tree-sitter-cpp@=0.24.2
cargo add brokk-tree-sitter-cpp@=0.24.3
```

Or add it directly to `Cargo.toml`:

```toml
[dependencies]
tree-sitter-cpp = { package = "brokk-tree-sitter-cpp", version = "=0.24.2" }
tree-sitter-cpp = { package = "brokk-tree-sitter-cpp", version = "=0.24.3" }
```

The crate prefixes its native parser symbols so it can coexist with the
Expand Down
246 changes: 246 additions & 0 deletions bindings/rust/lib.rs

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

37 changes: 36 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ module.exports = grammar(C, {
_preproc_linkage_block: $ => seq(
$.preproc_linkage_open,
repeat($._top_level_item),
$.preproc_linkage_close,
choice(
$.preproc_linkage_close,
alias($._preproc_linkage_close_ifdef, $.preproc_ifdef),
alias($._preproc_linkage_close_if, $.preproc_if),
),
),

// These fragments use the same preprocessor tokens as ordinary
Expand All @@ -187,6 +191,37 @@ module.exports = grammar(C, {
preprocessor('endif'),
)),

// A closing guard may also contain C++ declarations. Keep those declarations
// under an ordinary conditional node so consumers retain their guard.
_preproc_linkage_close_ifdef: $ => prec(1, seq(
choice(preprocessor('ifdef'), preprocessor('ifndef')),
field('name', $.identifier),
'}',
choice(
seq(
repeat1($._top_level_item),
optional(field('alternative', choice($.preproc_else, $.preproc_elif, $.preproc_elifdef))),
),
field('alternative', choice($.preproc_else, $.preproc_elif, $.preproc_elifdef)),
),
preprocessor('endif'),
)),

_preproc_linkage_close_if: $ => prec(1, seq(
preprocessor('if'),
field('condition', $._preproc_expression),
'\n',
'}',
choice(
seq(
repeat1($._top_level_item),
optional(field('alternative', choice($.preproc_else, $.preproc_elif, $.preproc_elifdef))),
),
field('alternative', choice($.preproc_else, $.preproc_elif, $.preproc_elifdef)),
),
preprocessor('endif'),
)),

_block_item: ($, original) => choice(
...original.members.filter((member) =>
member.content?.name != '_old_style_function_definition' &&
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json

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

2 changes: 1 addition & 1 deletion pyproject.toml

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

Loading
Loading