Class: Fa::Automaton

Inherits:
FFI::AutoPointer
  • Object
show all
Defined in:
lib/fa.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(faptr) ⇒ Automaton

Returns a new instance of Automaton.



12
13
14
# File 'lib/fa.rb', line 12

def initialize(faptr)
  @faptr = faptr
end

Instance Attribute Details

#faptrObject (readonly)

Returns the value of attribute faptr.



10
11
12
# File 'lib/fa.rb', line 10

def faptr
  @faptr
end

Class Method Details

.release(faptr) ⇒ Object



94
95
96
# File 'lib/fa.rb', line 94

def self.release(faptr)
  FFI::free(faptr)
end

Instance Method Details

#as_regexpObject

Raises:



85
86
87
88
89
90
91
92
# File 'lib/fa.rb', line 85

def as_regexp
  rx = ::FFI::MemoryPointer.new :string
  rx_len = ::FFI::MemoryPointer.new :size_t
  r = FFI::as_regexp(faptr, rx, rx_len)
  raise OutOfMemoryError if r < 0
  str_ptr = rx.read_pointer()
  return str_ptr.null? ? nil : str_ptr.read_string()
end

#complementObject



54
55
56
# File 'lib/fa.rb', line 54

def complement
  from_ptr( FFI::complement(faptr) )
end

#concat(other) ⇒ Object



22
23
24
# File 'lib/fa.rb', line 22

def concat(other)
  from_ptr( FFI::concat(faptr, other.faptr) )
end

#contains(other) ⇒ Object

Raises:



64
65
66
67
68
69
70
# File 'lib/fa.rb', line 64

def contains(other)
  # The C function works like fa1 <= fa2, and not how the
  # Ruby nomenclature would suggest it, so swap the arguments
  r = FFI::contains(other.faptr, faptr)
  raise Error if r < 0
  return r == 1
end

#empty?Boolean

Returns:

  • (Boolean)


81
# File 'lib/fa.rb', line 81

def empty?; is_basic(:empty); end

#epsilon?Boolean

Returns:

  • (Boolean)


82
# File 'lib/fa.rb', line 82

def epsilon?; is_basic(:epsilon); end

#equals(other) ⇒ Object

Raises:



58
59
60
61
62
# File 'lib/fa.rb', line 58

def equals(other)
  r = FFI::equals(faptr, other.faptr)
  raise Error if r < 0
  return r == 1
end

#from_ptr(ptr) ⇒ Object

Raises:



99
100
101
102
# File 'lib/fa.rb', line 99

def from_ptr(ptr)
  raise OutOfMemoryError if ptr.nil?
  Automaton.new(ptr)
end

#intersect(other) ⇒ Object



46
47
48
# File 'lib/fa.rb', line 46

def intersect(other)
  from_ptr( FFI::intersect(faptr, other.faptr) )
end

#is_basic(basic) ⇒ Object



72
73
74
75
76
77
78
79
# File 'lib/fa.rb', line 72

def is_basic(basic)
  # FFI::is_basic checks if the automaton is structurally the same as
  # +basic+; we just want to check here if they accept the same
  # language. If is_basic fails, we therefore check for equality
  r = FFI::is_basic(faptr, basic)
  return true if r == 1
  return equals(Fa::make_basic(basic))
end

#iter(min, max) ⇒ Object



30
31
32
# File 'lib/fa.rb', line 30

def iter(min, max)
  from_ptr( FFI::iter(faptr, min, max) )
end

#maybeObject



42
43
44
# File 'lib/fa.rb', line 42

def maybe
  iter(0, 1)
end

#minimizeObject

Raises:



16
17
18
19
20
# File 'lib/fa.rb', line 16

def minimize
  r = FFI::minimize(faptr)
  raise Error if r < 0
  self
end

#minus(other) ⇒ Object



50
51
52
# File 'lib/fa.rb', line 50

def minus(other)
  from_ptr( FFI::minus(faptr, other.faptr) )
end

#plusObject



38
39
40
# File 'lib/fa.rb', line 38

def plus
  iter(1, -1)
end

#starObject



34
35
36
# File 'lib/fa.rb', line 34

def star
  iter(0, -1)
end

#total?Boolean

Returns:

  • (Boolean)


83
# File 'lib/fa.rb', line 83

def total?; is_basic(:total); end

#union(other) ⇒ Object



26
27
28
# File 'lib/fa.rb', line 26

def union(other)
  from_ptr( FFI::union(faptr, other.faptr) )
end