Beispiel #1
0
        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);
            }
        }
Beispiel #2
0
        /// <summary>
        /// </summary>
        /// <param name="scriptFilePath"></param>
        /// <param name="includeFolders"></param>
        /// <returns>The preprocessed content of the script at the given path</returns>
        public string ProcessFile(string scriptFilePath, IReadOnlyList <string> includeFolders)
        {
            var content = PreProcessFile(MakeAbsolute(scriptFilePath),
                                         PreprocessorContext.CreateFor(scriptFilePath, includeFolders));

            return(Process(content));
        }
Beispiel #3
0
        private string ResolveScriptPath(string filePath, PreprocessorContext context)
        {
            if (Path.IsPathRooted(filePath))
            {
                return(filePath);
            }

            foreach (var includeFolder in context.IncludeFolders)
            {
                var path = Path.Combine(includeFolder, filePath + ".cs");
                if (_fileSystem.FileExists(path))
                {
                    return(path);
                }
            }

            throw new NotImplementedException();
        }
Beispiel #4
0
        public static PreprocessorContext CreateFor(string scriptFilePath, IReadOnlyList <string> includeFolders)
        {
            var tmp = new PreprocessorContext(includeFolders);

            return(tmp.CreateContextFor(scriptFilePath));
        }