module Mustermann::Concat::Native
Mixin for patterns to support native concatenation. @!visibility private
Public Instance Methods
+(other)
click to toggle source
@see Mustermann::Pattern#+ @!visibility private
Calls superclass method
# File lib/mustermann/concat.rb, line 10 def +(other) other &&= Mustermann.new(other, type: :identity, **options) if (patterns = look_ahead(other)) && !patterns.empty? concat = (self + patterns.inject(:+)) concat + other.patterns.slice(patterns.length..-1).inject(:+) else return super unless native = native_concat(other) self.class.new(native, **options) end end
look_ahead(other)
click to toggle source
@!visibility private
# File lib/mustermann/concat.rb, line 22 def look_ahead(other) return unless other.is_a?(Concat) other.patterns.take_while(&method(:native_concat?)) end
Private Instance Methods
native_concat(other)
click to toggle source
@!visibility private
# File lib/mustermann/concat.rb, line 28 def native_concat(other) "#{self}#{other}" if native_concat?(other) end
native_concat?(other)
click to toggle source
@!visibility private
# File lib/mustermann/concat.rb, line 33 def native_concat?(other) other.class == self.class and other.options == options end