Class: Ruby::Program
- Inherits:
-
Statements
- Object
- Node
- Aggregate
- List
- DelimitedList
- Statements
- Ruby::Program
- Defined in:
- lib/ruby/statements.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#src ⇒ Object
writeonly
Sets the attribute src.
Attributes included from Node::Composite
Instance Method Summary collapse
-
#initialize(src, filename, statements = [], end_data = nil) ⇒ Program
constructor
A new instance of Program.
-
#line_pos(row) ⇒ Object
TODO replace this with Clip?.
- #nodes ⇒ Object
- #replace_src(row, column, length, src) ⇒ Object
- #save_src ⇒ Object
- #to_ruby(prolog = false) ⇒ Object
Methods included from Conversions::Statements
#to_block, #to_chained_block, #to_named_block, #to_program
Methods inherited from List
Methods included from Alternation::List
Methods included from Conversions::List
Methods inherited from Aggregate
#position, #position=, #prolog, #prolog=
Methods inherited from Node
#<=>, #all_nodes, #column, #length, #row
Methods included from Conversions
Methods included from Node::Traversal
#has_token?, #has_type?, #has_value?, #is_instance_of?, #left_of?, #matches?, #position?, #right_of?, #select
Methods included from Node::Source
Methods included from Node::Composite
Constructor Details
#initialize(src, filename, statements = [], end_data = nil) ⇒ Program
Returns a new instance of Program.
13 14 15 16 17 18 |
# File 'lib/ruby/statements.rb', line 13 def initialize(src, filename, statements = [], end_data = nil) self.src = src self.filename = filename if filename self.end_data = end_data if end_data super(statements) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Ruby::List
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
10 11 12 |
# File 'lib/ruby/statements.rb', line 10 def filename @filename end |
#src=(value) ⇒ Object (writeonly)
Sets the attribute src
11 12 13 |
# File 'lib/ruby/statements.rb', line 11 def src=(value) @src = value end |
Instance Method Details
#line_pos(row) ⇒ Object
TODO replace this with Clip?
31 32 33 |
# File 'lib/ruby/statements.rb', line 31 def line_pos(row) (row > 0 ? src.split("\n")[0..(row - 1)].inject(0) { |pos, line| pos + line.length + 1 } : 0) end |
#nodes ⇒ Object
26 27 28 |
# File 'lib/ruby/statements.rb', line 26 def nodes [super, end_data].flatten.compact end |
#replace_src(row, column, length, src) ⇒ Object
35 36 37 38 39 |
# File 'lib/ruby/statements.rb', line 35 def replace_src(row, column, length, src) self.src[line_pos(row) + column, length] = src offset_column = src.length - length update_positions(row, column + length, offset_column) end |
#save_src ⇒ Object
41 42 43 |
# File 'lib/ruby/statements.rb', line 41 def save_src File.open(filename, 'w+') { |f| f.write(src) } end |
#to_ruby(prolog = false) ⇒ Object
22 23 24 |
# File 'lib/ruby/statements.rb', line 22 def to_ruby(prolog = false) super(true) end |