Skip to content

Support global parameters #14

@ficd0

Description

@ficd0

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.

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