lib/parslet/atoms/sequence.rb in parslet-1.0.1 vs lib/parslet/atoms/sequence.rb in parslet-1.1.0

- old
+ new

@@ -5,27 +5,33 @@ # str('a') >> str('b') # matches 'a', then 'b' # class Parslet::Atoms::Sequence < Parslet::Atoms::Base attr_reader :parslets def initialize(*parslets) + super() + @parslets = parslets + @error_msgs = { + :failed => "Failed to match sequence (#{self.inspect})" + } end def >>(parslet) # :nodoc: @parslets << parslet self end - def try(io) # :nodoc: - catch(:error) { - return [:sequence]+parslets.map { |p| - # Save each parslet as potentially offending (raising an error). - @offending_parslet = p - p.apply(io) - } - } + def try(source, context) # :nodoc: + success([:sequence]+parslets.map { |p| + # Save each parslet as potentially offending (raising an error). + @offending_parslet = p - error(io, "Failed to match sequence (#{self.inspect})") + value = p.apply(source, context) + + return error(source, @error_msgs[:failed]) if value.error? + + value.result + }) end precedence SEQUENCE def to_s_inner(prec) # :nodoc: parslets.map { |p| p.to_s(prec) }.join(' ')