Class: Rux::Lex::Transition

Inherits:
Object
  • Object
show all
Defined in:
lib/rux/lex/transition.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, to_state, advance_count) ⇒ Transition

Returns a new instance of Transition.



11
12
13
14
15
# File 'lib/rux/lex/transition.rb', line 11

def initialize(input, to_state, advance_count)
  @input = input
  @to_state = to_state
  @advance_count = advance_count
end

Instance Attribute Details

#advance_countObject (readonly)

Returns the value of attribute advance_count.



4
5
6
# File 'lib/rux/lex/transition.rb', line 4

def advance_count
  @advance_count
end

#inputObject (readonly)

Returns the value of attribute input.



4
5
6
# File 'lib/rux/lex/transition.rb', line 4

def input
  @input
end

#to_stateObject (readonly)

Returns the value of attribute to_state.



4
5
6
# File 'lib/rux/lex/transition.rb', line 4

def to_state
  @to_state
end

Class Method Details

.parse(str, input) ⇒ Object



6
7
8
9
# File 'lib/rux/lex/transition.rb', line 6

def self.parse(str, input)
  to_state, advance_count = str.match(/\A(\w+)\[?(-?\d+)?\]?/).captures
  new(input, :"tRUX_#{to_state.upcase}", (advance_count || 1).to_i)
end

Instance Method Details

#matches?(chr) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/rux/lex/transition.rb', line 17

def matches?(chr)
  input.matches?(chr)
end