Class: Walrus::WalrusGrammar::SilentDirective

Inherits:
Object
  • Object
show all
Defined in:
lib/walrus/walrus_grammar/silent_directive.rb

Instance Method Summary collapse

Instance Method Details

#compile(options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/walrus/walrus_grammar/silent_directive.rb', line 22

def compile(options = {})
  
  if @expression.respond_to? :each
    expression = @expression
  else
    expression = [@expression]
  end
  
  # TODO: potentially include line, col and file name info in the comments generated by the compiler
  
  compiled  = ''
  first     = true
  expression.each do |expr| 
    if first
      compiled << "instance_eval { %s } # Silent directive\n" % expr.compile
      first = false
    else
      compiled << "instance_eval { %s } # Silent directive (continued)\n" % expr.compile
    end
  end
  compiled
  
end