You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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:
Crucially, the error affects the entire global section, resulting in no syntax highlighting in applications that rely on tree-sitter to provide it:
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:
I think this change would greatly enhance the user experience without violating the ini specification.
The text was updated successfully, but these errors were encountered:
Problem
Key-value pairs are syntactically correct if they occur before the first section declaration. Please note that GitHub correctly highlights this snippet:
But the tree-sitter grammar does not, due to it returning
(ERROR)
nodes because it expects a named section first: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 withini
(and variousini
-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:
Crucially, the error affects the entire global section, resulting in no syntax highlighting in applications that rely on tree-sitter to provide it:
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:
I think this change would greatly enhance the user experience without violating the
ini
specification.The text was updated successfully, but these errors were encountered: