lib/junoser/input.rb in junoser-0.5.5 vs lib/junoser/input.rb in junoser-0.5.6
- old
+ new
@@ -11,10 +11,11 @@
@io_or_string.to_s
end
content = remove_blank_and_comment_line(content)
content = unify_carriage_return(content)
+ content = unify_square_brackets(content)
end
private
@@ -27,8 +28,28 @@
end
def unify_carriage_return(str)
str.gsub! /\r\n?/, "\n"
str
+ end
+
+ # Statements or [ ... ] may be split into multiple lines. This method unifies them into one line.
+ def unify_square_brackets(str)
+ lines = []
+
+ open_brackets = 0
+ str.split("\n").each do |line|
+ raise "ERROR: invalid statement: #{line}" if open_brackets < 0
+
+ if open_brackets == 0
+ lines << line
+ else
+ lines.last << " " << line
+ end
+
+ open_brackets += line.count('[') - line.count(']')
+ end
+
+ lines.join("\n")
end
end
end