Class: Regexgen::Ast::Concatenation
- Inherits:
-
Object
- Object
- Regexgen::Ast::Concatenation
- Defined in:
- lib/regexgen/ast.rb
Overview
Represents a concatenation (e.g. ‘foo`)
Instance Attribute Summary collapse
-
#a ⇒ Object
readonly
Returns the value of attribute a.
-
#b ⇒ Object
readonly
Returns the value of attribute b.
-
#precedence ⇒ Object
readonly
Returns the value of attribute precedence.
Instance Method Summary collapse
-
#initialize(a, b) ⇒ Concatenation
constructor
A new instance of Concatenation.
- #length ⇒ Object
- #literal(side) ⇒ Object
- #remove_substring(side, len) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(a, b) ⇒ Concatenation
Returns a new instance of Concatenation.
91 92 93 94 95 |
# File 'lib/regexgen/ast.rb', line 91 def initialize(a, b) @precedence = 2 @a = a @b = b end |
Instance Attribute Details
#a ⇒ Object (readonly)
Returns the value of attribute a.
89 90 91 |
# File 'lib/regexgen/ast.rb', line 89 def a @a end |
#b ⇒ Object (readonly)
Returns the value of attribute b.
89 90 91 |
# File 'lib/regexgen/ast.rb', line 89 def b @b end |
#precedence ⇒ Object (readonly)
Returns the value of attribute precedence.
89 90 91 |
# File 'lib/regexgen/ast.rb', line 89 def precedence @precedence end |
Instance Method Details
#length ⇒ Object
97 98 99 |
# File 'lib/regexgen/ast.rb', line 97 def length @a.length + @b.length end |
#literal(side) ⇒ Object
105 106 107 108 109 |
# 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) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 |
# 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 |