Class: Dhaka::ParserState
- Inherits:
-
Object
- Object
- Dhaka::ParserState
- Defined in:
- lib/parser/parser_state.rb
Overview
:nodoc:
Constant Summary collapse
- @@state_id =
0
Instance Attribute Summary collapse
-
#actions ⇒ Object
Returns the value of attribute actions.
-
#id ⇒ Object
Returns the value of attribute id.
-
#items ⇒ Object
Returns the value of attribute items.
Class Method Summary collapse
Instance Method Summary collapse
- #compile_to_ruby_source ⇒ Object
- #for_symbol(symbol_name, &blk) ⇒ Object
-
#initialize(parser, items, id = nil) ⇒ ParserState
constructor
A new instance of ParserState.
- #to_dot(options = {}) ⇒ Object
- #to_s(options = {}) ⇒ Object
- #transition_items ⇒ Object
- #unique_name ⇒ Object
Constructor Details
#initialize(parser, items, id = nil) ⇒ ParserState
Returns a new instance of ParserState.
13 14 15 16 17 18 |
# File 'lib/parser/parser_state.rb', line 13 def initialize(parser, items, id=nil) @parser = parser @items = items @actions = {} @id = id || ParserState.next_state_id end |
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
3 4 5 |
# File 'lib/parser/parser_state.rb', line 3 def actions @actions end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/parser/parser_state.rb', line 3 def id @id end |
#items ⇒ Object
Returns the value of attribute items.
3 4 5 |
# File 'lib/parser/parser_state.rb', line 3 def items @items end |
Class Method Details
.next_state_id ⇒ Object
7 8 9 10 11 |
# File 'lib/parser/parser_state.rb', line 7 def self.next_state_id result = @@state_id @@state_id += 1 result end |
Instance Method Details
#compile_to_ruby_source ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/parser/parser_state.rb', line 36 def compile_to_ruby_source result = " at_state(#{id}) {\n" actions.each do |symbol_name, action| result << " for_symbol('#{symbol_name}') { #{action.compile_to_ruby_source} }\n" end result << " }" result end |
#for_symbol(symbol_name, &blk) ⇒ Object
45 46 47 |
# File 'lib/parser/parser_state.rb', line 45 def for_symbol symbol_name, &blk actions[symbol_name] = @parser.instance_eval(&blk) end |
#to_dot(options = {}) ⇒ Object
32 33 34 |
# File 'lib/parser/parser_state.rb', line 32 def to_dot( = {}) %(#{unique_name} [label="#{items.values.collect{|item| item.to_s()}.join('\n')}"]) end |
#to_s(options = {}) ⇒ Object
49 50 51 |
# File 'lib/parser/parser_state.rb', line 49 def to_s( = {}) items.values.collect{|item| item.to_s()}.join("\n") end |
#transition_items ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/parser/parser_state.rb', line 20 def transition_items result = Hash.new {|h, k| h[k] = ItemSet.new()} items.values.each do |item| result[item.next_symbol] << item if item.next_symbol end result end |
#unique_name ⇒ Object
28 29 30 |
# File 'lib/parser/parser_state.rb', line 28 def unique_name "State#{id}" end |