Class: O::Parser
- Inherits:
-
Object
- Object
- O::Parser
- Defined in:
- lib/o/parser.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
Class Method Summary collapse
Instance Method Summary collapse
- #compile ⇒ Object
-
#initialize(content) ⇒ Parser
constructor
A new instance of Parser.
Constructor Details
#initialize(content) ⇒ Parser
Returns a new instance of Parser.
12 13 14 |
# File 'lib/o/parser.rb', line 12 def initialize content @content = content end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
3 4 5 |
# File 'lib/o/parser.rb', line 3 def content @content end |
Class Method Details
Instance Method Details
#compile ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/o/parser.rb', line 16 def compile script = "" indent_counts = 0 block_start = false scan do |token, statement| case token when :block_start block_start = true statement = statement.sub(":", " do") script << statement << "\n" when :statement script << statement << "\n" when :indent indent_counts += 1 script << "\t"*indent_counts when :undent script << "\t"*indent_counts when :dedent if block_start block_start = false script << "\t"*(indent_counts-1) + "end\n" else script << "\t"*(indent_counts-1) end indent_counts -= 1 end end script end |