Skip to content

Commit 8d34eb4

Browse files
committed
feat(isc): allow whitespace inside ref(N), better description multiline
1 parent 02d5f1d commit 8d34eb4

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

exe/codemod-imp-to-isc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,18 +213,23 @@ module Interscript
213213
@out << "\n#{indent}}"
214214
elsif @scanner.scan(/(?:\A|\n)([ \t]+)description[ \t]*:[ \t]*\n[ \t]+/)
215215
# `description:` with value on subsequent indented line(s).
216-
# Capture as brace block with raw text.
216+
# Capture as brace block with raw text. Continues until dedent
217+
# back to indent level or close brace.
217218
indent = @scanner[1]
218219
@out << "\n#{indent}description { "
219220
# Read until dedent or close brace
220221
until @scanner.eos?
221-
if @scanner.check(/\n[ \t]{0,#{indent.length}}\S/) || @scanner.check(/\n[ \t]{0,#{indent.length}}\}/)
222+
if @scanner.check(/\n(?:[ \t]*\n)*([ \t]{0,#{indent.length}}\S)/) ||
223+
@scanner.check(/\n(?:[ \t]*\n)*[ \t]{0,#{indent.length}}\}/)
222224
@out << " }"
223225
break
224226
elsif @scanner.scan(/[^\n]+/)
225227
@out << @scanner.matched
226228
elsif @scanner.scan(/\n[ \t]+/)
227229
@out << " "
230+
elsif @scanner.scan(/\n[ \t]*\n/)
231+
# Blank line — preserve as space
232+
@out << " "
228233
elsif @scanner.scan(/\n/)
229234
@out << " "
230235
else

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ module Items
9191

9292
# ref(N) — reference to Nth capture group. Only valid in `to` position.
9393
rule(:capture_reference) do
94-
(str("ref") >> str("(") >> match(/[0-9]/).as(:digit) >> str(")")).as(:ref)
94+
(str("ref") >> str("(") >> whitespace? >>
95+
match(/[0-9]/).as(:digit) >> whitespace? >>
96+
str(")")).as(:ref)
9597
end
9698

9799
rule(:keyword) do

0 commit comments

Comments
 (0)