Skip to content

Commit ca00e1b

Browse files
committed
feat(isc): use inline_whitespace between field name and value (no newlines)
The whitespace? rule was consuming newlines after a field name, which broke empty fields (like 'description' followed by another field on next line). Now using inline_whitespace? (spaces/tabs only) for the gap between identifier and field_value, so the parser can detect empty fields correctly. Verification: 184/289 maps equivalent (64%).
1 parent 8d34eb4 commit ca00e1b

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

lib/interscript/isc/grammar/concerns/metadata.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ module Metadata
112112
# close brace). This makes the parser permissive about future
113113
# field additions; semantic validation happens in DocumentBuilder.
114114
rule(:generic_field) do
115-
identifier.as(:field_name) >> whitespace? >>
115+
identifier.as(:field_name) >> inline_whitespace? >>
116116
(empty_field | field_value.as(:field_value))
117117
end
118118

@@ -122,10 +122,9 @@ module Metadata
122122
end
123123

124124
rule(:empty_field) do
125-
# An identifier with no value (just newline or `}` after). The
126-
# separate rule prevents the generic_field's value rule from
127-
# consuming into the next field.
128-
(newline.present? | str("}").present?).as(:empty)
125+
# An identifier with no value (just newline or `}` after). Use
126+
# lookahead without consuming.
127+
(newline.present? | str("}").present?)
129128
end
130129

131130
# Raw text inside `{ ... }` — for description blocks. Consumes any

lib/interscript/isc/grammar/concerns/primitives.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ module Primitives
2929
end
3030
rule(:whitespace?) { whitespace.maybe }
3131

32+
# Inline whitespace: spaces and tabs only, NO newlines. Used between
33+
# a field name and its value to prevent eating the newline that
34+
# signals an empty value.
35+
rule(:inline_space) { match(/[ \t]/).repeat(1) }
36+
rule(:inline_whitespace) do
37+
(inline_space | line_comment).repeat(1)
38+
end
39+
rule(:inline_whitespace?) { inline_whitespace.maybe }
40+
3241
# Comma, used in lists. Trailing whitespace allowed.
3342
rule(:comma) { str(",") >> whitespace? }
3443

0 commit comments

Comments
 (0)