module Bob::Compiler::Substitution

Constants

SUBSTITUTION_PARSER
SUBSTITUTION_SCANNER

Public Instance Methods

quote_and_substitute(arg, node) click to toggle source
# File lib/bob/compiler/substitution.rb, line 25
def quote_and_substitute(arg, node)
  parts = arg.split(SUBSTITUTION_SCANNER).reject(&:empty?)

  if parts.empty?
    %{""}
  else
    parts.map { |str|

      if SUBSTITUTION_SCANNER =~ str
        if str[0] == "\\"
          quote(str[1..-1] || "")
        else
          if (parsed = SUBSTITUTION_PARSER.match(str))
            if parsed[:fallback]
              "env.get(#{quote parsed[:path]}, #{quote unescape parsed[:fallback]})"
            else
              "env.get(#{quote parsed[:path]})"
            end
          else
            warn "Treating invalid substitution as string: #{str.inspect}", node.parent.line
            quote str
          end
        end
      else
        quote str
      end

    }.join(" + ")
  end
end
unescape(str) click to toggle source
# File lib/bob/compiler/substitution.rb, line 56
def unescape(str)
  str.gsub(/\\(.)/, "\\1")
end