Skip to content

feat: Warn about unreachable variables when generating the parser #4565

@wetneb

Description

@wetneb

Problem

Variable names (i.e. node types) can be unreachable when they aren't linked to the root rule (generally named source_file) and aren't part of extras.

When such variable names appear, it might be a symptom of a problem: either the dead rule should be removed, or it should be linked to reachable rules in other ways.

Even though dead rules don't make it into the generated parser at all (as far as I can see), it could be nice to have tree-sitter generate warn grammar authors about such cases, possibly with a CLI flag to enable or disable this warning. When using meta-programming to generate the rules dynamically, it can be that such unreachable variables are expected and should just be ignored. This might be a reason for not enabling this check by default.

Expected behavior

Output a warning on stderr when this feature is enabled and some rules are unreachable.

This warning would be formatted in a similar way to those for unnecessary conflict declarations, for instance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions