Class: LLIP::RegexpSpecification::State

Inherits:
Hash
  • Object
show all
Defined in:
lib/llip/regexp_specification.rb

Constant Summary collapse

@@next_name =
0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ State

The defaults are: * :final => false * :error => :error

If :error is set to :self, the error code it’s set to the name of the State, i.e. state == state.name => true. This is used to have a everything-like behaviour.



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/llip/regexp_specification.rb', line 83

def initialize(hash = {})
  @name = (@@next_name += 1)
  
  if hash[:error] == :self
    super self
  elsif hash[:error].nil?
    super :error
  else
    hash[:error] = hash[:error].to_sym if hash[:error].respond_to? :to_sym
    super hash[:error]
  end
  
  @final = hash[:final] || false
  
  self
end

Instance Attribute Details

#final=(value) ⇒ Object (writeonly)

see State#final?



71
72
73
# File 'lib/llip/regexp_specification.rb', line 71

def final=(value)
  @final = value
end

#nameObject (readonly)

It’s a Numeric and it globally identifies a State.



68
69
70
# File 'lib/llip/regexp_specification.rb', line 68

def name
  @name
end

#regexpObject

The RegexpSpecification of this state



74
75
76
# File 'lib/llip/regexp_specification.rb', line 74

def regexp
  @regexp
end

Instance Method Details

#==(other) ⇒ Object



117
118
119
120
121
122
# File 'lib/llip/regexp_specification.rb', line 117

def ==(other)
  if other.respond_to? :error
    return false unless other.error === error
  end
  super
end

#final?Boolean

:call-seq: final? => true final? => false

It identifies if a State is final or not.

Returns:

  • (Boolean)


105
106
107
# File 'lib/llip/regexp_specification.rb', line 105

def final?
  @final
end

#hashObject

As a State is globally identified by it’s name so it’s valid to use it as the hash code.



110
111
112
# File 'lib/llip/regexp_specification.rb', line 110

def hash
  @name.hash
end

#lastObject

Return an Array which contains all the last states reachable starting from this state, those which must be marked as final.

It internally calls RegexpSpecification.last_accessor



127
128
129
# File 'lib/llip/regexp_specification.rb', line 127

def last
  RegexpSpecification.last_accessor(self).uniq	
end