Class: Flott::Parser::TextMode

Inherits:
Mode
  • Object
show all
Defined in:
lib/flott.rb

Overview

This Mode class handles the Parser’s TextMode state.

Instance Attribute Summary

Attributes inherited from Mode

#parser

Instance Method Summary collapse

Methods inherited from Mode

#initialize, #scanner, #state

Constructor Details

This class inherits a constructor from Flott::Parser::Mode

Instance Method Details

#scanObject

Scan the template in TextMode.



813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
# File 'lib/flott.rb', line 813

def scan
  case
  when state.skip_cr && scanner.skip(/[\t ]*\r?\n/)
    state.skip_cr = false
  when scanner.scan(ESCOPEN)
    state.text << '\\['
  when scanner.scan(CURLYOPEN)
    state.text << '\\{'
  when scanner.scan(INCOPEN)
    state.last_open = :INCOPEN
    parser.include_template(scanner[1])
    state.skip_cr = scanner[2]
  when scanner.scan(PRIOPEN)
    state.last_open = :PRIOPEN
    parser.goto_ruby_mode
    state.text2compiled
    state.compiled << "@__output__<<@__escape__.call((\n"
  when scanner.scan(RAWOPEN)
    state.last_open = :RAWOPEN
    parser.goto_ruby_mode
    state.text2compiled
    state.compiled << "@__output__<<((\n"
  when scanner.scan(COMOPEN)
    state.last_open = :COMOPEN
    parser.goto_ruby_mode
    state.text2compiled
    state.compiled << "\n=begin\n"
  when scanner.scan(MINPRIOPEN)
    state.last_open = :PRIOPEN
    if t = state.text.last
      t.sub!(/[\t ]*\z/, '')
    end
    parser.goto_ruby_mode
    state.text2compiled
    state.compiled << "@__output__<<@__escape__.call((\n"
  when scanner.scan(MINRAWOPEN)
    state.last_open = :RAWOPEN
    if t = state.text.last
      t.sub!(/[\t ]*\z/, '')
    end
    parser.goto_ruby_mode
    state.text2compiled
    state.compiled << "@__output__<<((\n"
  when scanner.scan(MINCOMOPEN)
    state.last_open = :COMOPEN
    if t = state.text.last
      t.sub!(/[\t ]*\z/, '')
    end
    parser.goto_ruby_mode
    state.text2compiled
    state.compiled << "\n=begin\n"
  when scanner.scan(MINOPEN)
    state.last_open = :OPEN
    if t = state.text.last
      t.sub!(/[\t ]*\z/, '')
    end
    parser.goto_ruby_mode
    state.text2compiled(false)
  when scanner.scan(OPEN)
    state.last_open = :OPEN
    parser.goto_ruby_mode
    state.text2compiled
  when scanner.scan(CLOSE)
    state.text << '\\' << scanner[0]
  when scanner.scan(TEXT)
    state.text << scanner[0]
  when scanner.scan(CURLYCLOSE)
    state.text << '\\' << scanner[0]
  when scanner.scan(ESC)
    state.text << '\\\\' << scanner[0]
  else
    raise CompileError, "unknown tokens '#{scanner.peek(40)}'"
  end
end