Class: Cfruby::Cfp_Compile
- Inherits:
-
Object
- Object
- Cfruby::Cfp_Compile
- Defined in:
- lib/libcfenjin/cfp_compile.rb
Instance Method Summary collapse
-
#do_compile(code, do_eval = true) ⇒ Object
Takes a piece of
code
and compiles it - after successful compilation the code-snippet is ready for execution. -
#dump_compiled(code) ⇒ Object
Dump parsed and compiled code (100% Ruby).
-
#initialize(cf, parser = nil) ⇒ Cfp_Compile
constructor
A new instance of Cfp_Compile.
Constructor Details
#initialize(cf, parser = nil) ⇒ Cfp_Compile
Returns a new instance of Cfp_Compile.
14 15 16 17 |
# File 'lib/libcfenjin/cfp_compile.rb', line 14 def initialize cf,parser=nil @cf = cf @parser = parser end |
Instance Method Details
#do_compile(code, do_eval = true) ⇒ Object
Takes a piece of code
and compiles it - after successful compilation the code-snippet is ready for execution. When do_eval
is false the actual evaluation is omitted (no error checking!)
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/libcfenjin/cfp_compile.rb', line 23 def do_compile code, do_eval=true @cf.cfp_logger.trace TRACE_ENGINE,"Compiling #{code.fn} action #{code.action}" begin # Translate Cfruby style code into plain Ruby translator = Cfp_Translate.new(@cf,@parser) # Translate conditional blocks lines = translator.conditionals(code) # Line by line translation, depending on function - i.e. control, files, tidy etc. translated_lines = [] # code.each do | line,num | lines.each do | line | translated_lines.push translator.do_translate(code.action,line) end # Encapsulate teh code into a class object buf = code.encapsulate(translated_lines).join("\n") @cf.cfp_logger.trace TRACE_ALL,buf eval buf if do_eval rescue SyntaxError, RuntimeError msg = 'ERROR cfscript ',code.fn," line #{code.linenum} - #{$!}\n" code.dump @cf.cfp_logger.error LOG_CRIT,msg,'cfruby' raise end buf end |
#dump_compiled(code) ⇒ Object
Dump parsed and compiled code (100% Ruby)
50 51 52 53 |
# File 'lib/libcfenjin/cfp_compile.rb', line 50 def dump_compiled code buf = do_compile code,false print buf,"\n" end |