class Regexgen::Ast::Concatenation

Represents a concatenation (e.g. `foo`)

Attributes

a[R]
b[R]
precedence[R]

Public Class Methods

new(a, b) click to toggle source
# File lib/regexgen/ast.rb, line 91
def initialize(a, b)
  @precedence = 2
  @a = a
  @b = b
end

Public Instance Methods

length() click to toggle source
# File lib/regexgen/ast.rb, line 97
def length
  @a.length + @b.length
end
literal(side) click to toggle source
# File lib/regexgen/ast.rb, line 105
def literal(side)
  return @a.literal(side) if side == :start && @a.respond_to?(:literal)

  @b.literal(side) if side == :end && @b.respond_to?(:literal)
end
remove_substring(side, len) click to toggle source
# File lib/regexgen/ast.rb, line 111
def remove_substring(side, len)
  a = @a
  b = @b
  a = @a.remove_substring(side, len) if side == :start && @a.respond_to?(:remove_substring)
  b = @b.remove_substring(side, len) if side == :end && @b.respond_to?(:remove_substring)

  return b if a.respond_to?(:empty?) && a.empty?
  return a if b.respond_to?(:empty?) && b.empty?

  Concatenation.new(a, b)
end
to_s() click to toggle source
# File lib/regexgen/ast.rb, line 101
def to_s
  Ast.parens(@a, self) + Ast.parens(@b, self)
end