protected override bool ProcessLine(IFileParser parser, FileParserContext context, string line) { var argument = GetDirectiveArgument(line); var filePath = Environment.ExpandEnvironmentVariables(argument); var fullPath = _fileSystem.GetFullPath(filePath); if (!string.IsNullOrWhiteSpace(fullPath)) { parser.ParseFile(fullPath, context); } return true; }
protected override bool ProcessLine(IFileParser parser, FileParserContext context, string line) { var argument = GetDirectiveArgument(line); var assemblyPath = Environment.ExpandEnvironmentVariables(argument); var referencePath = _fileSystem.GetFullPath(assemblyPath); var referencePathOrName = _fileSystem.FileExists(referencePath) ? referencePath : argument; if (!string.IsNullOrWhiteSpace(referencePathOrName) && !context.References.Contains(referencePathOrName)) { context.References.Add(referencePathOrName); } return true; }
public bool ProcessLine(IFileParser parser, FileParserContext context, string line, bool isBeforeCode) { if (!IsUsingLine(line)) { return false; } var @namespace = GetNamespace(line); if (!context.Namespaces.Contains(@namespace)) { context.Namespaces.Add(@namespace); } return true; }
public virtual void ParseScript(List<string> scriptLines, FileParserContext context) { var codeIndex = scriptLines.FindIndex(IsNonDirectiveLine); for (var index = 0; index < scriptLines.Count; index++) { var line = scriptLines[index]; var isBeforeCode = index < codeIndex || codeIndex < 0; var wasProcessed = _lineProcessors.Any(x => x.ProcessLine(this, context, line, isBeforeCode)); if (!wasProcessed) { context.BodyLines.Add(line); } } }
public virtual void ParseFile(string path, FileParserContext context) { var fullPath = _fileSystem.GetFullPath(path); var filename = Path.GetFileName(path); if (context.LoadedScripts.Contains(fullPath)) { return; } // Add script to loaded collection before parsing to avoid loop. context.LoadedScripts.Add(fullPath); var scriptLines = _fileSystem.ReadFileLines(fullPath).ToList(); InsertLineDirective(fullPath, scriptLines); InDirectory(fullPath, () => ParseScript(scriptLines, context)); }
protected virtual FilePreProcessorResult Process(Action<FileParserContext> parseAction) { var context = new FileParserContext(); parseAction(context); var code = GenerateCode(context); return new FilePreProcessorResult { Namespaces = context.Namespaces, LoadedScripts = context.LoadedScripts, References = context.References, Code = code }; }
protected virtual string GenerateCode(FileParserContext context) { return string.Join(_fileSystem.NewLine, context.BodyLines); }