private string PreProcessFile(string scriptFilePath, PreprocessorContext context) { try { var scriptContent = _fileSystem.ReadAllText(scriptFilePath); var processedScript = new StringBuilder(); var lastIndex = 0; foreach (Match match in ImportRegexp.Matches(scriptContent)) { processedScript.Append(scriptContent, lastIndex, match.Index - lastIndex); var includedFilePath = match.Groups[groupnum : 1].Value.Trim(); var subScriptFilePath = ResolveScriptPath(includedFilePath, context); var subScriptContent = PreProcessFile(subScriptFilePath, context.CreateContextFor(subScriptFilePath)); processedScript.Append(subScriptContent); lastIndex = match.Index + match.Length; } if (lastIndex < scriptContent.Length) { processedScript.Append(scriptContent, lastIndex, scriptContent.Length - lastIndex); } return(processedScript.ToString()); } catch (IOException e) { throw new ScriptCannotBeAccessedException(e.Message, e); } }