Class: Walrus::Grammar::Placeholder

Inherits:
Walrat::Node
  • Object
show all
Defined in:
lib/walrus/grammar/placeholder.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
# File 'lib/walrus/grammar/placeholder.rb', line 28

def compile options = {}
  if options[:nest_placeholders] == true
    method_name = "lookup_and_return_placeholder"     # placeholder nested inside another placeholder
  else
    method_name = "lookup_and_accumulate_placeholder" # placeholder used in a literal text stream
  end

  if @params == []
    "#{method_name}(#{@name.to_s.to_sym.inspect})\n"
  else
    options = options.clone
    options[:nest_placeholders] = true
    params      = (@params.kind_of? Array) ? @params : [@params]
    param_list  = params.map { |param| param.compile(options) }.join(', ').chomp
    "#{method_name}(#{@name.to_s.to_sym.inspect}, #{param_list})\n"
  end
end