358: def strinterp(string, file = nil, line = nil)
359:
360: ss = StringScanner.new(string)
361: out = ""
362: while not ss.eos?
363: if ss.scan(/^\$\{((\w*::)*\w+|[0-9]+)\}|^\$([0-9])|^\$((\w*::)*\w+)/)
364:
365: if ss.matched == '\\$'
366: out << '$'
367: else
368:
369: var = ss[1] || ss[3] || ss[4]
370: if var and var =~ /^[0-9]+$/ and not ephemeral_include?(var)
371: next
372: end
373: out << lookupvar(var).to_s || ""
374: end
375: elsif ss.scan(/^\\(.)/)
376:
377: case ss[1]
378: when 'n'
379: out << "\n"
380: when 't'
381: out << "\t"
382: when 's'
383: out << " "
384: when '\\'
385: out << '\\'
386: when '$'
387: out << '$'
388: else
389: str = "Unrecognised escape sequence '#{ss.matched}'"
390: str += " in file #{file}" if file
391: str += " at line #{line}" if line
392: Puppet.warning str
393: out << ss.matched
394: end
395: elsif ss.scan(/^\$/)
396: out << '$'
397: elsif ss.scan(/^\\\n/)
398: next
399: else
400: tmp = ss.scan(/[^\\$]+/)
401:
402: unless tmp
403: error = Puppet::ParseError.new("Could not parse string #{string.inspect}")
404: {:file= => file, :line= => line}.each do |m,v|
405: error.send(m, v) if v
406: end
407: raise error
408: end
409: out << tmp
410: end
411: end
412:
413: out
414: end