lib/edl/parser.rb in edl-0.1.1 vs lib/edl/parser.rb in edl-0.1.2

- old
+ new

@@ -15,27 +15,24 @@ [ EventMatcher.new(@fps), EffectMatcher.new, NameMatcher.new, TimewarpMatcher.new(@fps), CommentMatcher.new ] end # Parse a passed File or IO object line by line, or the whole string def parse(input_string_or_io) - return parse(input_string_or_io.read) if input_string_or_io.respond_to?(:read) + return parse(StringIO.new(input_string_or_io)) unless input_string_or_io.respond_to?(:read) - # TODO properly normalize line breaks in a stream interface - input_string_or_io.gsub!(/(\r\n|\r)/, "\n") - input_in_io = StringIO.new(input_string_or_io) + magic = ::EDL::LinebreakMagician.new(input_string_or_io) # Normalize line breaks stack, matchers = List.new, get_matchers - until input_in_io.eof? + while current_line = magic.gets - current_line = input_in_io.gets.strip m = matchers.find{|m| m.matches?(current_line) } next unless m begin m.apply(stack, current_line) - stack[-1].line_number = input_in_io.lineno if m.is_a?(EventMatcher) + stack[-1].line_number = magic.lineno if m.is_a?(EventMatcher) rescue Matcher::ApplyError => e STDERR.puts "Cannot parse #{current_line} - #{e}" end end stack \ No newline at end of file