justinmk / tree-sitter-ini

tree-sitter grammar/parser for INI files
Apache License 2.0
20 stars 10 forks source link

Does not handle settings names with white space #11

Closed gregnis closed 4 weeks ago

gregnis commented 1 month ago

The following example produces errors:

[General]
Version=15.0
[Compare]
Ignore all white space=1
document [0, 0] - [4, 0]
  section [0, 0] - [2, 0]
    section_name [0, 0] - [0, 9]
      text [0, 1] - [0, 8]
    setting [1, 0] - [2, 0]
      setting_name [1, 0] - [1, 7]
      setting_value [1, 8] - [1, 12]
  section [2, 0] - [4, 0]
    section_name [2, 0] - [2, 9]
      text [2, 1] - [2, 8]
    setting [3, 0] - [4, 0]
      setting_name [3, 0] - [3, 6]
      ERROR [3, 7] - [3, 22]
        ERROR [3, 7] - [3, 22]
      setting_value [3, 23] - [3, 24]
justinmk commented 1 month ago

what are real world examples of this?

gregnis commented 1 month ago

It appear to work correctly if I remove \s from

    setting: $ => seq(
      alias(/[^;#=\s\[]+/, $.setting_name),
      '=',
      alias(/.+/, $.setting_value),
      choice('\n','\r\n'),
    ),

like this:

    setting: $ => seq(
      alias(/[^;#=\[]+/, $.setting_name),
      '=',
      alias(/.+/, $.setting_value),
      choice('\n','\r\n'),
    ),
gregnis commented 1 month ago

what are real world examples of this?

You can sees examples at https://en.wikipedia.org/wiki/INI_file:

[fruit.Date]
taste = novel
Trademark Issues="truly unlikely"