Module: Fa

Defined in:
lib/fa.rb,
lib/fa/version.rb

Overview

Namespace for the libfa bindings

Defined Under Namespace

Modules: FFI Classes: Automaton, Error, OutOfMemoryError

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.[](rx) ⇒ Fa::Automaton

Compiles rx into a finite automaton

Parameters:

  • rx (String)

    a regular expression

Returns:



229
230
231
# File 'lib/fa.rb', line 229

def self.[](rx)
  compile(rx)
end

.compile(rx) ⇒ Fa::Automaton

Compiles rx into a finite automaton

Parameters:

  • rx (String)

    a regular expression

Returns:

Raises:



219
220
221
222
223
224
# File 'lib/fa.rb', line 219

def self.compile(rx)
  faptr = ::FFI::MemoryPointer.new :pointer
  r = FFI::compile(rx, rx.size, faptr)
  raise Error if r != 0 # REG_NOERROR is 0, at least for glibc
  Automaton.new(faptr.get_pointer(0))
end

.make_basic(kind) ⇒ Fa::Automaton

Makes a basic finite automaton, either an empty, epsilon, or total finite automaton. Those match no words, only the empty word, or all words.

Parameters:

  • kind (:empty, :epsilon, :total)

Returns:

Raises:



238
239
240
241
242
# File 'lib/fa.rb', line 238

def self.make_basic(kind)
  faptr = FFI::make_basic(kind)
  raise OutOfMemoryError if faptr.null?
  Automaton.new(faptr)
end