Class: Rutile::NFA::Node
- Inherits:
-
Object
- Object
- Rutile::NFA::Node
- Defined in:
- lib/rutile/nfa.rb
Instance Attribute Summary collapse
-
#default ⇒ Object
Returns the value of attribute default.
-
#edges ⇒ Object
Returns the value of attribute edges.
-
#not ⇒ Object
Returns the value of attribute not.
-
#on_stack ⇒ Object
Returns the value of attribute on_stack.
-
#pos ⇒ Object
Returns the value of attribute pos.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #add(char, pos) ⇒ Object
- #dup ⇒ Object
- #empty(char) ⇒ Object
-
#initialize(pos) ⇒ Node
constructor
A new instance of Node.
- #mark ⇒ Object
- #marked? ⇒ Boolean
- #next(char) ⇒ Object
- #set_not(pos) ⇒ Object
- #unmark ⇒ Object
- #update_pos(offset) ⇒ Object
Constructor Details
#initialize(pos) ⇒ Node
Returns a new instance of Node.
5 6 7 8 9 10 11 |
# File 'lib/rutile/nfa.rb', line 5 def initialize(pos) @pos = pos @edges = {} @value = :transition_state @on_stack = false @default = nil end |
Instance Attribute Details
#default ⇒ Object
Returns the value of attribute default.
4 5 6 |
# File 'lib/rutile/nfa.rb', line 4 def default @default end |
#edges ⇒ Object
Returns the value of attribute edges.
4 5 6 |
# File 'lib/rutile/nfa.rb', line 4 def edges @edges end |
#not ⇒ Object
Returns the value of attribute not.
4 5 6 |
# File 'lib/rutile/nfa.rb', line 4 def not @not end |
#on_stack ⇒ Object
Returns the value of attribute on_stack.
4 5 6 |
# File 'lib/rutile/nfa.rb', line 4 def on_stack @on_stack end |
#pos ⇒ Object
Returns the value of attribute pos.
4 5 6 |
# File 'lib/rutile/nfa.rb', line 4 def pos @pos end |
#value ⇒ Object
Returns the value of attribute value.
4 5 6 |
# File 'lib/rutile/nfa.rb', line 4 def value @value end |
Instance Method Details
#add(char, pos) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/rutile/nfa.rb', line 19 def add(char, pos) if @edges[char] == nil @edges[char] = [] end @edges[char] << pos end |
#dup ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rutile/nfa.rb', line 43 def dup dupl = Node.new @pos dupl.value = @value dupl.default = @default dupl.on_stack = @on_stack dupl.edges = Marshal.load(Marshal.dump(@edges)) return dupl end |
#empty(char) ⇒ Object
26 27 28 |
# File 'lib/rutile/nfa.rb', line 26 def empty(char) @edges[char] = [] end |
#mark ⇒ Object
54 55 56 |
# File 'lib/rutile/nfa.rb', line 54 def mark @on_stack = true end |
#marked? ⇒ Boolean
62 63 64 |
# File 'lib/rutile/nfa.rb', line 62 def marked? @on_stack end |
#next(char) ⇒ Object
13 14 15 16 17 |
# File 'lib/rutile/nfa.rb', line 13 def next(char) ret = @edges[char] return @default if !@default.nil? && ret.nil? return ret ? ret : [] end |
#set_not(pos) ⇒ Object
38 39 40 |
# File 'lib/rutile/nfa.rb', line 38 def set_not(pos) @default = pos end |
#unmark ⇒ Object
58 59 60 |
# File 'lib/rutile/nfa.rb', line 58 def unmark @on_stack = false end |
#update_pos(offset) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/rutile/nfa.rb', line 30 def update_pos(offset) @edges.keys.each do |k| @edges[k] = @edges[k].map {|n| (n == :not) ? :not : n + offset}.to_a end @pos += offset @default = @default.map {|x| x + offset} if @default end |