Class: Hamlit::Compiler::ScriptCompiler

Inherits:
Object
  • Object
show all
Defined in:
lib/hamlit/compiler/script_compiler.rb

Instance Method Summary collapse

Constructor Details

#initialize(identity) ⇒ ScriptCompiler

Returns a new instance of ScriptCompiler.


9
10
11
# File 'lib/hamlit/compiler/script_compiler.rb', line 9

def initialize(identity)
  @identity = identity
end

Instance Method Details

#compile(node, &block) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/hamlit/compiler/script_compiler.rb', line 13

def compile(node, &block)
  unless Ripper.respond_to?(:lex) # No Ripper.lex in truffleruby
    return dynamic_compile(node, &block)
  end

  no_children = node.children.empty?
  case
  when no_children && node.value[:escape_interpolation]
    compile_interpolated_plain(node)
  when no_children && RubyExpression.string_literal?(node.value[:text])
    delegate_optimization(node)
  when no_children && Temple::StaticAnalyzer.static?(node.value[:text])
    static_compile(node)
  else
    dynamic_compile(node, &block)
  end
end