Class: Flott::Parser::RubyMode

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

Overview

This Mode class handles the Parser’s RubyMode 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 RubyMode.



892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
# File 'lib/flott.rb', line 892

def scan
  case
  when state.opened == 0 && scanner.scan(MINCLOSE)
    state.skip_cr = true
    case state.last_open
    when :PRIOPEN
      state.compiled << "\n))\n"
    when :RAWOPEN
      state.compiled << "\n).to_s)\n"
    when :COMOPEN
      state.compiled << "\n=end\n"
    else
      state.compiled << "\n"
    end
    parser.goto_text_mode
    state.last_open = nil
  when state.opened == 0 && scanner.scan(CLOSE)
    parser.goto_text_mode
    case state.last_open
    when :PRIOPEN
      state.compiled << "\n))\n"
    when :RAWOPEN
      state.compiled << "\n).to_s)\n"
    when :COMOPEN
      state.compiled << "\n=end\n"
    else
      state.compiled << "\n"
    end
    state.last_open = nil
  when scanner.scan(ESCCLOSE)
    state.compiled << scanner[0]
  when scanner.scan(CLOSE) && state.opened != 0,
      scanner.scan(MINCLOSE) && state.opened != 0
    state.opened -= 1
    state.compiled << scanner[0]
  when scanner.scan(ESCOPEN)
    state.compiled << scanner[0]
  when scanner.scan(OPEN)
    state.opened += 1
    state.compiled << scanner[0]
  when scanner.scan(TEXT)
    state.compiled << scanner[0]
  when scanner.scan(CURLY)
    state.compiled << '\\' << scanner[0]
  when scanner.scan(ESC_CLOSURE)
    s = scanner[0]
    ssize = s.size
    if ssize % 2 == 0
      state.compiled << s * 2
    else
      state.compiled << s[0, ssize - 1] * 2
      state.compiled << eval(%'"\\#{scanner.scan(/./)}"')
    end
  else
    raise CompileError, "unknown tokens '#{scanner.peek(40)}'"
  end
end