Class: Resyma::Core::RegexpSelect

Inherits:
Regexp
  • Object
show all
Defined in:
lib/resyma/core/automaton/regexp.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Regexp

#to_automaton

Constructor Details

#initialize(regexp_list) ⇒ RegexpSelect

Select one regexp from a list of regexps

Parameters:

  • regexp_list (Array<Regexp>)

    A list of instances of Regexp



73
74
75
# File 'lib/resyma/core/automaton/regexp.rb', line 73

def initialize(regexp_list)
  @regexp_list = regexp_list
end

Instance Attribute Details

#regexp_listObject (readonly)

Returns the value of attribute regexp_list.



77
78
79
# File 'lib/resyma/core/automaton/regexp.rb', line 77

def regexp_list
  @regexp_list
end

Instance Method Details

#==(other) ⇒ Object



79
80
81
# File 'lib/resyma/core/automaton/regexp.rb', line 79

def ==(other)
  other.is_a?(self.class) && other.regexp_list == @regexp_list
end

#inject(ab, start_state) ⇒ Object



83
84
85
86
87
88
89
90
91
92
# File 'lib/resyma/core/automaton/regexp.rb', line 83

def inject(ab, start_state)
  accept = ab.new_state!
  @regexp_list.each do |regexp|
    option_start = ab.new_state!
    ab.add_transition!(start_state, Epsilon, option_start)
    option_end = regexp.inject(ab, option_start)
    ab.add_transition!(option_end, Epsilon, accept)
  end
  accept
end