Skip to content

Commit e4e7e59

Browse files
committed
feat: setting value may be null/empty
Based on https://stackoverflow.com/a/9491779/152142 it seems like a empty/null value is allowed. close #9
1 parent e2c8dc7 commit e4e7e59

File tree

3 files changed

+62
-16
lines changed

3 files changed

+62
-16
lines changed

README.md

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,45 @@
11
tree-sitter-ini
22
==================
33

4-
This grammar implements the INI format.
4+
This grammar implements the [INI format](https://en.wikipedia.org/wiki/INI_file).
55

66
Overview
77
--------
88

99
Example INI file:
1010

11-
[section name]
12-
some_key = some_value
13-
another-key = another value
11+
```ini
12+
[section name]
13+
some_key = some_value
14+
# a comment
15+
another-key=another value
1416

15-
[another section]
16-
# a comment
17-
some_key = some_value
18-
another-key = another value
17+
[another section]
18+
# Keys may contain whitespace.
19+
key 1 =
20+
# Value may be empty.
21+
key 2 =
22+
```
1923

2024
See [test/corpus/](./test/corpus/) for more examples.
2125

22-
### Notes
26+
Notes
27+
-----
2328

24-
- Comments must start at column 1. Trailing comments are not supported. (Should they be?)
25-
26-
Known issues
27-
------------
28-
29-
- `setting_value` [includes whitespace](https://github.com/justinmk/tree-sitter-ini/issues/3).
29+
- Comments (`;` or `#`) must start at column 1. Trailing comments are not supported yet. [#13](https://github.com/justinmk/tree-sitter-ini/issues/13)
30+
- Equals sign (=) and semicolon (;) are reserved characters and cannot appear in the key. Any whitespace surrounding the key is stripped by the parser. [ref](https://en.wikipedia.org/wiki/INI_file#Key-value_pairs)
31+
- Section name must appear on a line by itself.
32+
- Duplicate names are not checked.
33+
- Line continuations (`\`) are not supported.
34+
- `setting_value` includes whitespace. [#3](https://github.com/justinmk/tree-sitter-ini/issues/3).
3035
Should values exclude surrounding whitespace?
36+
- [Quoted keys/values](https://en.wikipedia.org/wiki/INI_file#Quoted_values) are not supported yet.
37+
- Escape sequences are not supported.
3138

3239
Reference
3340
---------
3441

42+
- https://en.wikipedia.org/wiki/INI_file
3543
- https://github.com/textmate/ini.tmbundle
3644

3745
Release

grammar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module.exports = grammar({
3434
setting: $ => seq(
3535
alias(/[^;#=\s\[]+( *[^;#=\s\[])*/, $.setting_name),
3636
'=',
37-
alias(/.+/, $.setting_value),
37+
optional(alias(/.+/, $.setting_value)),
3838
/\r?\n/,
3939
),
4040

test/corpus/main.txt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,44 @@ foo = bar
1515
(setting_name)
1616
(setting_value))))
1717

18+
================================================================================
19+
setting value may be null/empty #9
20+
================================================================================
21+
22+
[section 1]
23+
setting 1 =
24+
setting 2 = x
25+
setting 3 =
26+
# comment
27+
setting 4 = y
28+
setting-5 =
29+
30+
[section 2]
31+
32+
--------------------------------------------------------------------------------
33+
34+
(document
35+
(section
36+
(section_name
37+
(text))
38+
(setting
39+
(setting_name))
40+
(setting
41+
(setting_name)
42+
(setting_value))
43+
(setting
44+
(setting_name))
45+
(comment
46+
(text))
47+
(setting
48+
(setting_name)
49+
(setting_value))
50+
(setting
51+
(setting_name)))
52+
(section
53+
(section_name
54+
(text))))
55+
1856
================================================================================
1957
weird key names
2058
================================================================================

0 commit comments

Comments
 (0)