Skip to content

Commit 272c16c

Browse files
committed
feat(isc): fix comment parsing, description multiline value, empty fields
- Main loop: scan # comments without consuming newline (was eating 2 lines) - Codemod: handle 'description:' with multi-line quoted value on next line - Tests converter: preserve # comments verbatim - Empty fields (just identifier) accepted via lookahead Verification: 177/289 maps equivalent (61%).
1 parent e77d41d commit 272c16c

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

exe/codemod-imp-to-isc

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ module Interscript
102102
until @scanner.eos?
103103
if @scanner.scan(/\s+/m)
104104
@out << @scanner.matched
105-
elsif @scanner.scan(/#\s.*?$/)
105+
elsif @scanner.scan(/#[^\n]*/)
106+
# Line comment (without consuming newline)
106107
@out << @scanner.matched
107108
elsif @scanner.scan(/metadata\b/)
108109
@out << "metadata"
@@ -204,12 +205,32 @@ module Interscript
204205
elsif @scanner.scan(/\}/)
205206
depth -= 1
206207
@out << "}"
207-
elsif @scanner.scan(/(?:\A|\n)([ \t]+)description[ \t]*:[ \t]*\|/)
208+
elsif @scanner.scan(/(?:\A|\n)([ \t]+)description[ \t]*:[ \t]*\|[ \t]*\n/)
208209
# Heredoc form: `description: |` followed by indented body.
209210
indent = @scanner[1]
210211
@out << "\n#{indent}description {"
211212
convert_indented_block_until_dedent(indent)
212213
@out << "\n#{indent}}"
214+
elsif @scanner.scan(/(?:\A|\n)([ \t]+)description[ \t]*:[ \t]*\n[ \t]+/)
215+
# `description:` with value on subsequent indented line(s).
216+
# Capture as brace block with raw text.
217+
indent = @scanner[1]
218+
@out << "\n#{indent}description { "
219+
# Read until dedent or close brace
220+
until @scanner.eos?
221+
if @scanner.check(/\n[ \t]{0,#{indent.length}}\S/) || @scanner.check(/\n[ \t]{0,#{indent.length}}\}/)
222+
@out << " }"
223+
break
224+
elsif @scanner.scan(/[^\n]+/)
225+
@out << @scanner.matched
226+
elsif @scanner.scan(/\n[ \t]+/)
227+
@out << " "
228+
elsif @scanner.scan(/\n/)
229+
@out << " "
230+
else
231+
break
232+
end
233+
end
213234
elsif @scanner.scan(/(?:\A|\n)([ \t]+)notes[ \t]*:[ \t]*\|[ \t]*\n/)
214235
# Heredoc-form notes: `notes: |` followed by indented body that's
215236
# one big multi-line note.

0 commit comments

Comments
 (0)