Skip to content

Commit 04b1c3d

Browse files
committed
Fixed reading line continuations.
1 parent 1e8af3b commit 04b1c3d

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

lib/daedalus/dependency_grapher.rb

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ class ElseIf < If; end
292292
class Define < Node
293293
def initialize(macro, parser)
294294
super parser
295+
295296
macro.strip!
296297
if index = macro.index(" ")
297298
@name = macro[0..index-1]
@@ -428,22 +429,23 @@ def parse_file(name)
428429
def parse(lines)
429430
@line = 0
430431

431-
inlined_line = ""
432-
unless lines.empty?
433-
while (line = lines.shift.chomp(''))
434-
@line += 1
435-
line.rstrip!
436-
if line.end_with?('\\')
437-
# continue reading if line ends in \
438-
inlined_line += line.chop
439-
else
440-
# stop reading
441-
inlined_line += line
442-
break
443-
end
432+
re = /^\s*#(include|ifdef|ifndef|endif|else|define|undef|if|elif)(.*)$/o
433+
full_line = ""
434+
435+
lines.each do |line|
436+
@line += 1
437+
438+
full_line.chomp!
439+
440+
if line[-2] == ?\\
441+
full_line += line.chomp("\\\n") + "\n"
442+
next
443+
else
444+
full_line += line
444445
end
445446

446-
m = inlined_line.match(/^\s*#(include|ifdef|ifndef|endif|else|define|undef|if|elif)(.*)$/)
447+
m = full_line.match re
448+
full_line = ""
447449

448450
send :"process_#{m[1]}", m[2] if m
449451
end

0 commit comments

Comments
 (0)