Class: Walrus::Grammar::SilentDirective

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

Instance Method Summary collapse

Instance Method Details

#compile(options = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/walrus/grammar/silent_directive.rb', line 28

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