Class: Flott::Parser::State
- Inherits:
-
Object
- Object
- Flott::Parser::State
- Defined in:
- lib/flott.rb
Overview
This class encapsulates the state, that is shared by all parsers that were activated during the parse phase.
Instance Attribute Summary collapse
-
#compiled ⇒ Object
readonly
An array of the already compiled Ruby code fragments.
-
#directories ⇒ Object
readonly
A stack array, that contains the work directories of all active templates (during parsing).
-
#last_open ⇒ Object
The type of the last opened bracket.
-
#opened ⇒ Object
The number of current open (unescaped) brackets.
-
#pathes ⇒ Object
readonly
An array of involved template file pathes, that is, also the statically included template file pathes.
-
#skip_cr ⇒ Object
Returns the value of attribute skip_cr.
-
#text ⇒ Object
readonly
An array of all scanned text fragments.
Instance Method Summary collapse
-
#compiled_string ⇒ Object
Return the whole compiled code as a string.
-
#initialize ⇒ State
constructor
Creates a new Flott::Parser::State instance to hold the current parser state.
-
#pop_workdir ⇒ Object
Pops the top directory from the directories stack.
-
#push_workdir(parser) ⇒ Object
Pushs the workdir of parser onto the directories stack.
-
#text2compiled(dont_sub = true) ⇒ Object
Transform text mode parts to compiled code parts.
-
#top_workdir ⇒ Object
Returns the top directory from the directories stack.
Constructor Details
#initialize ⇒ State
Creates a new Flott::Parser::State instance to hold the current parser state.
545 546 547 548 549 550 551 552 553 |
# File 'lib/flott.rb', line 545 def initialize @opened = 0 @last_open = nil @text = [] @compiled = [] @pathes = [] @directories = [] @skip_cr = false end |
Instance Attribute Details
#compiled ⇒ Object (readonly)
An array of the already compiled Ruby code fragments.
565 566 567 |
# File 'lib/flott.rb', line 565 def compiled @compiled end |
#directories ⇒ Object (readonly)
A stack array, that contains the work directories of all active templates (during parsing).
573 574 575 |
# File 'lib/flott.rb', line 573 def directories @directories end |
#last_open ⇒ Object
The type of the last opened bracket.
559 560 561 |
# File 'lib/flott.rb', line 559 def last_open @last_open end |
#opened ⇒ Object
The number of current open (unescaped) brackets.
556 557 558 |
# File 'lib/flott.rb', line 556 def opened @opened end |
#pathes ⇒ Object (readonly)
An array of involved template file pathes, that is, also the statically included template file pathes.
569 570 571 |
# File 'lib/flott.rb', line 569 def pathes @pathes end |
#skip_cr ⇒ Object
Returns the value of attribute skip_cr.
575 576 577 |
# File 'lib/flott.rb', line 575 def skip_cr @skip_cr end |
#text ⇒ Object (readonly)
An array of all scanned text fragments.
562 563 564 |
# File 'lib/flott.rb', line 562 def text @text end |
Instance Method Details
#compiled_string ⇒ Object
Return the whole compiled code as a string.
588 589 590 |
# File 'lib/flott.rb', line 588 def compiled_string compiled.join.untaint end |
#pop_workdir ⇒ Object
Pops the top directory from the directories stack.
606 607 608 609 610 611 |
# File 'lib/flott.rb', line 606 def pop_workdir directories.empty? and raise CompileError, "state directories were empty" directories.pop compiled << "@__workdir__ = '#{top_workdir}'\n" self end |
#push_workdir(parser) ⇒ Object
Pushs the workdir of parser onto the directories stack.
593 594 595 596 597 598 |
# File 'lib/flott.rb', line 593 def push_workdir(parser) workdir = parser.workdir compiled << "@__workdir__ = '#{workdir}'\n" directories << workdir self end |
#text2compiled(dont_sub = true) ⇒ Object
Transform text mode parts to compiled code parts.
578 579 580 581 582 583 584 585 |
# File 'lib/flott.rb', line 578 def text2compiled(dont_sub = true) return if text.empty? text.last.sub!(/[\t ]+$/, '') unless dont_sub compiled << '@__output__<<%q[' compiled.concat(text) compiled << "]\n" text.clear end |
#top_workdir ⇒ Object
Returns the top directory from the directories stack.
601 602 603 |
# File 'lib/flott.rb', line 601 def top_workdir directories.last end |