Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to change the root rule at runtime #1105

Open
XVilka opened this issue May 13, 2021 · 1 comment
Open

Ability to change the root rule at runtime #1105

XVilka opened this issue May 13, 2021 · 1 comment

Comments

@XVilka
Copy link
Contributor

XVilka commented May 13, 2021

Inspired by the issue in C grammar: tree-sitter/tree-sitter-c#65

Currently parser is only able to successfully parse terminated statements, like:

const char * myarray[25];

But if you feed something like

const char * [25]

or

const char *

It emits an error.
It would be beneficial to support parsing such statements too.
@thestr4ng3r proposed the following change in the grammar:

diff --git a/grammar.js b/grammar.js
index 6a5fa25..5dc99a3 100644
--- a/grammar.js
+++ b/grammar.js
@@ -51,6 +51,7 @@ module.exports = grammar({
  word: $ => $.identifier,

  rules: {
+    the_actual_root: $ => $.type_descriptor,
    translation_unit: $ => repeat($._top_level_item),

    _top_level_item: $ => choice(

but it breaks many other cases

To clarify, what we actually need is in addition to parsing a full translation_unit like int a() { x = (const char *[25])y; }, in the same >application parse only the part inside the cast like const char *[25], which is type_descriptor.

So essentially, we would need a way to change the root rule to use at runtime, which isn't really tree-sitter-c specific. I wonder if >that is even theoretically possible with how the code generator works.

@ahlinc
Copy link
Contributor

ahlinc commented May 13, 2021

This is the known limitation for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants