Class: RubyToBlock::Context
- Inherits:
-
Object
- Object
- RubyToBlock::Context
- Defined in:
- app/models/concerns/ruby_to_block/context.rb
Overview
ソースコード解析の状態を表現するクラス
Instance Attribute Summary collapse
-
#blocks ⇒ Object
Returns the value of attribute blocks.
-
#character_stack ⇒ Object
Returns the value of attribute character_stack.
-
#characters ⇒ Object
Returns the value of attribute characters.
-
#current_block ⇒ Object
Returns the value of attribute current_block.
-
#current_line ⇒ Object
Returns the value of attribute current_line.
-
#lines ⇒ Object
Returns the value of attribute lines.
-
#receiver_stack ⇒ Object
Returns the value of attribute receiver_stack.
-
#statement_stack ⇒ Object
Returns the value of attribute statement_stack.
-
#value_name_stack ⇒ Object
Returns the value of attribute value_name_stack.
Instance Method Summary collapse
- #[](symbol) ⇒ Object
- #[]=(symbol, val) ⇒ Object
- #add_block(block) ⇒ Object
- #add_value(block) ⇒ Object
- #character ⇒ Object
-
#initialize(lines) ⇒ Context
constructor
A new instance of Context.
-
#look_next_line ⇒ String
次の行を参照する.
-
#next_line ⇒ String
次の行に移動して、改行を含むその行の文字列を返す.
- #receiver ⇒ Object
- #statement ⇒ Object
- #statement_block ⇒ Object
- #statement_type ⇒ Object
- #value_name ⇒ Object
Constructor Details
#initialize(lines) ⇒ Context
Returns a new instance of Context.
16 17 18 19 20 21 22 23 24 25 |
# File 'app/models/concerns/ruby_to_block/context.rb', line 16 def initialize(lines) @lines = lines @characters = {} @character_stack = [] @receiver_stack = [] @statement_stack = [] @value_name_stack = [] @blocks = [] @current_block = nil end |
Instance Attribute Details
#blocks ⇒ Object
Returns the value of attribute blocks.
13 14 15 |
# File 'app/models/concerns/ruby_to_block/context.rb', line 13 def blocks @blocks end |
#character_stack ⇒ Object
Returns the value of attribute character_stack.
9 10 11 |
# File 'app/models/concerns/ruby_to_block/context.rb', line 9 def character_stack @character_stack end |
#characters ⇒ Object
Returns the value of attribute characters.
8 9 10 |
# File 'app/models/concerns/ruby_to_block/context.rb', line 8 def characters @characters end |
#current_block ⇒ Object
Returns the value of attribute current_block.
14 15 16 |
# File 'app/models/concerns/ruby_to_block/context.rb', line 14 def current_block @current_block end |
#current_line ⇒ Object
Returns the value of attribute current_line.
6 7 8 |
# File 'app/models/concerns/ruby_to_block/context.rb', line 6 def current_line @current_line end |
#lines ⇒ Object
Returns the value of attribute lines.
7 8 9 |
# File 'app/models/concerns/ruby_to_block/context.rb', line 7 def lines @lines end |
#receiver_stack ⇒ Object
Returns the value of attribute receiver_stack.
10 11 12 |
# File 'app/models/concerns/ruby_to_block/context.rb', line 10 def receiver_stack @receiver_stack end |
#statement_stack ⇒ Object
Returns the value of attribute statement_stack.
11 12 13 |
# File 'app/models/concerns/ruby_to_block/context.rb', line 11 def statement_stack @statement_stack end |
#value_name_stack ⇒ Object
Returns the value of attribute value_name_stack.
12 13 14 |
# File 'app/models/concerns/ruby_to_block/context.rb', line 12 def value_name_stack @value_name_stack end |
Instance Method Details
#[](symbol) ⇒ Object
65 66 67 |
# File 'app/models/concerns/ruby_to_block/context.rb', line 65 def [](symbol) send(symbol) end |
#[]=(symbol, val) ⇒ Object
69 70 71 |
# File 'app/models/concerns/ruby_to_block/context.rb', line 69 def []=(symbol, val) send("#{symbol}=", val) end |
#add_block(block) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/models/concerns/ruby_to_block/context.rb', line 41 def add_block(block) if current_block # HACK: コメントは下の行に関係することが多いため対象外としている if current_block.type == 'character_new' && block.type != 'character_new' && block.type != 'ruby_comment' current_block.add_statement(:DO, block) block = current_block else current_block.sibling = block end else blocks.push(block) end self.current_block = block self end |
#add_value(block) ⇒ Object
58 59 60 61 62 63 |
# File 'app/models/concerns/ruby_to_block/context.rb', line 58 def add_value(block) fail unless current_block || value_name current_block.add_value(value_name, block) self end |
#character ⇒ Object
77 78 79 |
# File 'app/models/concerns/ruby_to_block/context.rb', line 77 def character @character_stack.last end |
#look_next_line ⇒ String
次の行を参照する
37 38 39 |
# File 'app/models/concerns/ruby_to_block/context.rb', line 37 def look_next_line lines.first end |
#next_line ⇒ String
次の行に移動して、改行を含むその行の文字列を返す
30 31 32 |
# File 'app/models/concerns/ruby_to_block/context.rb', line 30 def next_line self.current_line = lines.shift end |
#receiver ⇒ Object
73 74 75 |
# File 'app/models/concerns/ruby_to_block/context.rb', line 73 def receiver @receiver_stack.last end |
#statement ⇒ Object
81 82 83 |
# File 'app/models/concerns/ruby_to_block/context.rb', line 81 def statement @statement_stack.last end |
#statement_block ⇒ Object
89 90 91 |
# File 'app/models/concerns/ruby_to_block/context.rb', line 89 def statement_block statement[1] end |
#statement_type ⇒ Object
85 86 87 |
# File 'app/models/concerns/ruby_to_block/context.rb', line 85 def statement_type statement.first end |
#value_name ⇒ Object
93 94 95 |
# File 'app/models/concerns/ruby_to_block/context.rb', line 93 def value_name @value_name_stack.last end |