Class: Rux::Lex::State
- Inherits:
-
Object
- Object
- Rux::Lex::State
- Defined in:
- lib/rux/lex/state.rb
Instance Attribute Summary collapse
-
#is_terminal ⇒ Object
(also: #terminal?)
readonly
Returns the value of attribute is_terminal.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#transitions ⇒ Object
readonly
Returns the value of attribute transitions.
Class Method Summary collapse
Instance Method Summary collapse
- #[](chr) ⇒ Object
-
#initialize(name, is_terminal, transitions) ⇒ State
constructor
A new instance of State.
Constructor Details
#initialize(name, is_terminal, transitions) ⇒ State
Returns a new instance of State.
19 20 21 22 23 24 |
# File 'lib/rux/lex/state.rb', line 19 def initialize(name, is_terminal, transitions) @name = name @is_terminal = is_terminal @transitions = transitions @cache = {} end |
Instance Attribute Details
#is_terminal ⇒ Object (readonly) Also known as: terminal?
Returns the value of attribute is_terminal.
15 16 17 |
# File 'lib/rux/lex/state.rb', line 15 def is_terminal @is_terminal end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/rux/lex/state.rb', line 15 def name @name end |
#transitions ⇒ Object (readonly)
Returns the value of attribute transitions.
15 16 17 |
# File 'lib/rux/lex/state.rb', line 15 def transitions @transitions end |
Class Method Details
.parse(state_str, transition_strs, inputs) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/rux/lex/state.rb', line 4 def self.parse(state_str, transition_strs, inputs) is_terminal = state_str.end_with?('*') state_name = "tRUX_#{state_str.chomp('*').upcase}".to_sym transitions = transition_strs.each_with_object([]).with_index do |(ts, ret), idx| ret << Transition.parse(ts, inputs[idx]) if ts end new(state_name, is_terminal, transitions) end |
Instance Method Details
#[](chr) ⇒ Object
26 27 28 29 30 |
# File 'lib/rux/lex/state.rb', line 26 def [](chr) @cache[chr] ||= transitions.find do |trans| trans.matches?(chr) end end |