/// <exception cref="TemplateParseError" />
        public string ReplaceVariables(string template)
        {
            var sb = new StringBuilder();

            foreach (var token in Parse(template))
            {
                sb.Append(token.MatchWith(
                              variable => _variableResolver.ResolveVariable(variable.Name),
                              text => text.Text));
            }
            return(sb.ToString());
        }
        public string ResolveVariable(string name)
        {
            name.ThrowIfNull("name");

            if (name == _key)
            {
                return(_value);
            }

            if (_parentScope != null)
            {
                return(_parentScope.ResolveVariable(name));
            }

            throw new ArgumentException("Invalid environment variable", "name");
        }
        public IEnumerable <AbsoluteFilePath> Spawn(Template template, AbsoluteDirectoryPath containingDir)
        {
            _fileSystem.CreateIfNotExists(containingDir);

            return(CopyTemplateFiles(template, _templateVariableResolver.ResolveVariable("filename"), containingDir));
        }