示例#1
0
        public PreprocessedScript Process(FileInfo file)
        {
            var result = new PreprocessedScript(file);

            scriptDirectoryPath = file.DirectoryName;
            ParseFile(file.FullName, result);
            result.FinalizeScript();

            return(result);
        }
示例#2
0
        private void ProcessLine(string currentScriptFilePath, PreprocessedScript result, string line, bool isBeforeCode)
        {
            if (IsUsingLine(line))
            {
                var @using = GetPath(UsingString, line);

                result.Namespaces.Add(@using);

                return;
            }

            if (IsRLine(line))
            {
                if (isBeforeCode)
                {
                    var reference = GetPath(RString, line);

                    if (reference.EndsWith(@".dll") || reference.EndsWith(@".exe"))
                    {
                        result.AbsoluteReferences.Add(
                            new AssemblyAbsoluteReference(currentScriptFilePath, reference));

                        return;
                    }

                    result.References.Add(
                        new AssemblyNameReference(currentScriptFilePath, reference));
                }

                return;
            }

            if (IsLoadLine(line))
            {
                if (isBeforeCode)
                {
                    var filePath = GetPath(LoadString, line);

                    if (!result.LoadedScripts.Contains(filePath))
                    {
                        ParseFile(Path.Combine(scriptDirectoryPath, filePath), result);
                    }
                }

                return;
            }

            // If we've reached this, the line is part of the body...
            result.Body.Add(line);
        }
示例#3
0
        private void ParseFile(string path, PreprocessedScript result)
        {
            var fileLines = File.ReadAllLines(path).ToList();

            InsertLineDirective(path, fileLines);

            var codeIndex = fileLines.FindIndex(IsNonDirectiveLine);

            for (var index = 0; index < fileLines.Count; index++)
            {
                ProcessLine(path, result, fileLines[index], index < codeIndex || codeIndex < 0);
            }

            result.LoadedScripts.Add(path);
        }