Class: RegularExpression::AST::Anchor

Inherits:
Object
  • Object
show all
Defined in:
lib/regular_expression/ast.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Anchor

Returns a new instance of Anchor.



232
233
234
# File 'lib/regular_expression/ast.rb', line 232

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

“A” | “z” | “$”



230
231
232
# File 'lib/regular_expression/ast.rb', line 230

def value
  @value
end

Instance Method Details

#to_dot(parent) ⇒ Object



236
237
238
# File 'lib/regular_expression/ast.rb', line 236

def to_dot(parent)
  parent.add_node(object_id, label: value, shape: "box")
end

#to_nfa(start, finish) ⇒ Object



240
241
242
243
244
245
246
247
248
249
250
# File 'lib/regular_expression/ast.rb', line 240

def to_nfa(start, finish)
  transition =
    case value
    when "\\A"
      NFA::Transition::BeginAnchor.new(finish)
    when "\\z", "$"
      NFA::Transition::EndAnchor.new(finish)
    end

  start.add_transition(transition)
end