Skip to content

Commit 02d5f1d

Browse files
committed
feat(isc): handle notes: "quoted string" form, multi-line note bodies
1 parent 86e5d17 commit 02d5f1d

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

exe/codemod-imp-to-isc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,13 @@ module Interscript
231231
break
232232
end
233233
end
234+
elsif @scanner.scan(/(?:\A|\n)([ \t]+)notes[ \t]*:[ \t]*"/)
235+
# `notes: "X"` — single quoted-string note value
236+
indent = @scanner[1]
237+
@out << "\n#{indent}notes {\n#{indent} note \""
238+
# Read until matching close quote (may span multiple lines).
239+
convert_quoted_note_body
240+
@out << "\"\n#{indent}}"
234241
elsif @scanner.scan(/(?:\A|\n)([ \t]+)notes[ \t]*:[ \t]*\|[ \t]*\n/)
235242
# Heredoc-form notes: `notes: |` followed by indented body that's
236243
# one big multi-line note.
@@ -365,6 +372,21 @@ module Interscript
365372
@out << "\""
366373
end
367374

375+
def convert_quoted_note_body
376+
# Read a quoted string body (already past opening quote). Continues
377+
# across newlines until matching unescaped `"`.
378+
until @scanner.eos?
379+
if @scanner.scan(/\\./)
380+
@out << @scanner.matched
381+
elsif @scanner.scan(/"/)
382+
return
383+
else
384+
c = @scanner.getch
385+
@out << (c == "\n" ? "\\n" : c)
386+
end
387+
end
388+
end
389+
368390
def read_heredoc_into_string(indent)
369391
# Read lines that are indented deeper than `indent` (or blank). Concatenate.
370392
until @scanner.eos?

0 commit comments

Comments
 (0)