Skip to content

Commit

Permalink
feat: Allow properties with empty values
Browse files Browse the repository at this point in the history
  • Loading branch information
ValdezFOmar committed Jul 7, 2024
1 parent 2e324d3 commit 7b528ab
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[test/**/*.txt]
trim_trailing_whitespace = false
indent_style = space
indent_size = 2

[*.{json,toml,yml,gyp}]
indent_style = space
indent_size = 2
Expand Down
2 changes: 1 addition & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ module.exports = grammar({
field('key', alias($._key_name_trimmed, $.identifier)),
'=',
/[ \t]*/, // Eat all the leading white-space
field('value', $._value),
field('value', optional($._value)),
$._newline,
),

Expand Down
3 changes: 2 additions & 1 deletion queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
(escaped_character) @string.special

(pair
key: (identifier) @property)
key: (identifier) @property
value: (_)? @string)

(boolean) @boolean
(integer) @number
Expand Down
5 changes: 4 additions & 1 deletion src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ static inline bool parse_key_name(TSLexer *lexer)

while (lexer->lookahead != '=') {
if (is_newline(lexer->lookahead) || lexer->eof(lexer)) {
return false;
// NOTE: Tecnically is not valid since there is be no value
// on the right side, but it gives better error recovery
lexer->result_symbol = KEY_NAME_TRIMMED;
return true;
}
if (is_space(lexer->lookahead)) {
lexer->advance(lexer, false);
Expand Down
32 changes: 32 additions & 0 deletions test/corpus/main.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,31 @@ key = # this is not a comment
key: (identifier)
value: (unknown))))

======================================================
Properties with an empty value
======================================================
[a]
a=
b =
c=
d =
spaces =
------------------------------------------------------
(document
(section
(section_name
(character))
(pair
key: (identifier))
(pair
key: (identifier))
(pair
key: (identifier))
(pair
key: (identifier))
(pair
key: (identifier))))

======================================================
Comments
======================================================
Expand Down Expand Up @@ -338,6 +363,13 @@ Characters after section header
[a] key = value
------------------------------------------------------

======================================================
Property without '=' and value
:error
======================================================
property
------------------------------------------------------

======================================================
Comment after section header
:error
Expand Down

0 comments on commit 7b528ab

Please sign in to comment.