syntax .ini-comment

state maybe-comment text
    char -b " \t" this
    char '#;' comment
    noeat -b END

state comment
    char -n "\n" this
    noeat END

syntax ini

# Note: this syntax supports comments starting with '#' or ';', but they
# must be either at the start of a line or preceded by at least 1 space
# or tab character. This is in-keeping with parser libraries like inih
# (https://github.com/benhoyt/inih) and various other implementations.

state line-start
    char " \t\n" this
    char [ section
    char '#;' comment
    char = value error
    noeat text

state section ini.section
    char ] section-end ini.section
    char "\n" line-start error
    eat this

state section-end
    char " \t" .ini-comment:this
    char "\n" line-start
    eat this error

state text
    char -b " \t" .ini-comment:this
    char -b = key operator
    char -bn "\n" this
    noeat line-start

state key
    recolor variable
    recolor operator 1
    noeat value

state value
    char \' single-quote
    char \" double-quote
    char -b a-z this
    # FIXME: does this highlight constants with trailing characters?
    inlist constant this constant
    char " \t" .ini-comment:this
    char "\n" line-start
    eat this

state single-quote string
    char \' value string
    char "\n" line-start
    eat this

state double-quote string
    char \" value string
    char "\n" line-start
    eat this

state comment
    char "\n" line-start
    eat this

list constant true false
