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
- #dot_name ⇒ 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 ⇒ Object
- #transition_items ⇒ Object
Constructor Details
#initialize(parser, items, id = nil) ⇒ ParserState
Returns a new instance of ParserState.
16 17 18 19 20 21 |
# File 'lib/parser/parser_state.rb', line 16 def initialize(parser, items, id=nil) @parser = parser @items = items @actions = {} @id = id ? id : ParserState.next_state_id end |
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
6 7 8 |
# File 'lib/parser/parser_state.rb', line 6 def actions @actions end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/parser/parser_state.rb', line 6 def id @id end |
#items ⇒ Object
Returns the value of attribute items.
6 7 8 |
# File 'lib/parser/parser_state.rb', line 6 def items @items end |
Class Method Details
.next_state_id ⇒ Object
10 11 12 13 14 |
# File 'lib/parser/parser_state.rb', line 10 def self.next_state_id result = @@state_id @@state_id += 1 result end |
Instance Method Details
#compile_to_ruby_source ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/parser/parser_state.rb', line 39 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 |
#dot_name ⇒ Object
31 32 33 |
# File 'lib/parser/parser_state.rb', line 31 def dot_name self.to_s end |
#for_symbol(symbol_name, &blk) ⇒ Object
48 49 50 |
# File 'lib/parser/parser_state.rb', line 48 def for_symbol symbol_name, &blk actions[symbol_name] = @parser.instance_eval(&blk) end |
#to_dot(options = {}) ⇒ Object
35 36 37 38 |
# File 'lib/parser/parser_state.rb', line 35 def to_dot( = {}) label = self.items.values.collect{|item| item.to_s()}.join('\n') "#{dot_name} [label=\"#{label}\"]" end |
#to_s ⇒ Object
52 53 54 |
# File 'lib/parser/parser_state.rb', line 52 def to_s "State#{id}" end |
#transition_items ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/parser/parser_state.rb', line 23 def transition_items result = Hash.new {|h, k| h[k] = ItemSet.new()} for item in @items.values (result[item.next_symbol] << item) if item.next_symbol end result end |