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

Support global parameters #14

Open
ficcdaf opened this issue Feb 27, 2025 · 1 comment · May be fixed by #15
Open

Support global parameters #14

ficcdaf opened this issue Feb 27, 2025 · 1 comment · May be fixed by #15

Comments

@ficcdaf
Copy link

ficcdaf commented Feb 27, 2025

Problem

Key-value pairs are syntactically correct if they occur before the first section declaration. Please note that GitHub correctly highlights this snippet:

this_region="is marked as an error" 
[section name]
this_region="is no longer an error"

But the tree-sitter grammar does not, due to it returning (ERROR) nodes because it expects a named section first:

Image

Solution

I propose modifying the grammar to make the first section header optional. Key-value pairs before the first section should still be parsed as valid nodes.

Rationale

Some dialects of ini (or, depending on the implementation) support global parameters. A key-value pair set before the first section declaration is considered to be a global parameter. Please see this specification from Apache.

The point being that it is not syntactically incorrect for an ini file to contain key-value pairs before declaring its first section. In fact, in my experience working with ini (and various ini-related) formats on Linux, many applications support global parameters.

Currently, the parser returns an error node if there is no leading section, please see this screenshot from Helix:

Image

Crucially, the error affects the entire global section, resulting in no syntax highlighting in applications that rely on tree-sitter to provide it:

Image

This also affects the language injection experience. For example, people often include snippets of configuration code in fenced markdown blocks. However, if the fenced code doesn't have a section, the parser gives an error node and the snippet isn't highlighted:

Image

Image

I think this change would greatly enhance the user experience without violating the ini specification.

@ficcdaf ficcdaf linked a pull request Feb 27, 2025 that will close this issue
@ficcdaf
Copy link
Author

ficcdaf commented Feb 27, 2025

I've opened a PR that implements this feature. It doesn't break any existing tests or behavior. I look forward to discussing it with you @justinmk

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

Successfully merging a pull request may close this issue.

1 participant