Class: Flexr::Automaton::ReferenceDFA

Inherits:
Object
  • Object
show all
Defined in:
lib/flexr/automaton/dfa.rb

Instance Method Summary collapse

Constructor Details

#initialize(regexp, unicode: false) ⇒ ReferenceDFA

Returns a new instance of ReferenceDFA.



158
159
160
161
162
163
164
165
166
167
168
# File 'lib/flexr/automaton/dfa.rb', line 158

def initialize(regexp, unicode: false)
  source, options = if reference_pattern?(regexp, unicode: unicode)
    converted = Unicode::ReferenceRegexp.compiled(
      regexp, encoding: regexp.encoding, options: regexp.options, unicode: unicode
    )
    [converted.source, converted.options]
  else
    [regexp.source, regexp.options]
  end
  @regexp = ::Regexp.new("\\A(?:#{source})\\z", options)
end

Instance Method Details

#accept?(bytes) ⇒ Boolean

Returns:

  • (Boolean)


170
171
172
173
174
175
# File 'lib/flexr/automaton/dfa.rb', line 170

def accept?(bytes)
  data = bytes.dup.force_encoding(@regexp.encoding)
  @regexp.match?(data)
rescue ArgumentError, EncodingError
  false
end

#statsObject



177
178
179
# File 'lib/flexr/automaton/dfa.rb', line 177

def stats
  { states: 0, classes: 0, accepting_states: 0, reference: true }
end