   dict = MistResolver.generateDict pathname
 
   template.replace MistResolver.delimiterPattern, (m, p, c)->
-    if c of dict then (p || '') + dict[c]
+    c = (p || '') + c
+    if c of dict then dict[c]
     else throw "unknown file delimiter: #{c}"
 
 ###

#   The command to delimit
###
MistResolver.delimitCommand = (command)->
  command.replace MistResolver.delimiterPattern, "$1${D_$2}"

MistResolver.compileVars = (inputs, outputs)->
  result = {}
  for input in inputs.map MistResolver.generateDict
    for k, v of input
      if k is 'o' then v = outputs
      if k is 'O' then v = outputs.map path.dirname
      k = "D_#{k}"
      result[k] = [] if k not of result
      result[k] = result[k].concat v

  if pathname of @
    dict = @[pathname]
  else
    dict['%'] = '%'
    dict['x'] = path.extname pathname
    dict['b'] = path.basename pathname
    dict['X'] = dict['b'].replace /.+?(\..+)$/, '$1'
    dict['B'] = path.basename dict['b'], dict['x']
    dict['f'] = pathname
    dict['F'] = path.basename dict['f'], dict['x']
    dict['o'] = '%o'
    dict['O'] = '%O'

    leafs = path.dirname(pathname).split path.sep
    len = leafs.length
    pathJoinArray = (arr)-> path.join.apply path, arr
    for leaf,i in leafs
      ii = i + 1
      ni = len - ii
      dict["#{ii}d"] = leaf
      dict["#{ii}-d"] = pathJoinArray leafs.slice i
      dict["-#{ii}d"] = leafs[ni]
      dict["-#{ii}-d"] = pathJoinArray leafs.slice ni
  return dict
MistResolver.generateDict = MistResolver.generateDict.bind {}

