protected virtual void ParseFile(string path, FilePreProcessorContext context) { _logger.DebugFormat("Processing {0}...", Path.GetFileName(path)); var scriptLines = _fileSystem.ReadFileLines(path).ToList(); ParseScript(scriptLines, context, path); }
protected virtual void ProcessLine(FilePreProcessorContext context, string line, bool isBeforeCode) { Guard.AgainstNullArgument("context", context); if (PreProcessorUtil.IsUsingLine(line)) { var @using = PreProcessorUtil.GetPath(PreProcessorUtil.UsingString, line); if (!context.UsingStatements.Contains(@using)) { context.UsingStatements.Add(@using); } return; } if (PreProcessorUtil.IsRLine(line)) { if (isBeforeCode) { var reference = PreProcessorUtil.GetPath(PreProcessorUtil.RString, line); if (!string.IsNullOrWhiteSpace(reference) && !context.References.Contains(reference)) { context.References.Add(reference); } } return; } if (PreProcessorUtil.IsLoadLine(line)) { if (isBeforeCode) { var filePath = PreProcessorUtil.GetPath(PreProcessorUtil.LoadString, line); if (!string.IsNullOrWhiteSpace(filePath) && !context.LoadedScripts.Contains(filePath)) { ParseFile(filePath, context); } } return; } // If we've reached this, the line is part of the body... context.Body.Add(line); }
private string GenerateCode(FilePreProcessorContext context) { var stringBuilder = new StringBuilder(); var usingLines = context.UsingStatements .Select(item => string.Format("using {0};", item)) .ToList(); if (usingLines.Count > 0) { stringBuilder.AppendLine(string.Join(_fileSystem.NewLine, usingLines)); stringBuilder.AppendLine(); // Insert a blank separator line } stringBuilder.Append(string.Join(_fileSystem.NewLine, context.Body)); return stringBuilder.ToString(); }
private FilePreProcessorResult Parse(Action<FilePreProcessorContext> parseAction) { var context = new FilePreProcessorContext(); _logger.DebugFormat("Starting pre-processing"); parseAction(context); var code = GenerateCode(context); _logger.DebugFormat("Pre-processing finished successfully"); return new FilePreProcessorResult { UsingStatements = context.UsingStatements, LoadedScripts = context.LoadedScripts, References = context.References, Code = code }; }
protected virtual string GenerateCode(FilePreProcessorContext context) { Guard.AgainstNullArgument("context", context); var stringBuilder = new StringBuilder(); var usingLines = context.UsingStatements .Select(item => string.Format("using {0};", item)) .ToList(); if (usingLines.Count > 0) { stringBuilder.AppendLine(string.Join(_fileSystem.NewLine, usingLines)); stringBuilder.AppendLine(); // Insert a blank separator line } stringBuilder.Append(string.Join(_fileSystem.NewLine, context.Body)); return(stringBuilder.ToString()); }
protected virtual FilePreProcessorResult Parse(Action<FilePreProcessorContext> parseAction) { Guard.AgainstNullArgument("parseAction", parseAction); var context = new FilePreProcessorContext(); _logger.DebugFormat("Starting pre-processing"); parseAction(context); var code = GenerateCode(context); _logger.DebugFormat("Pre-processing finished successfully"); return new FilePreProcessorResult { UsingStatements = context.UsingStatements, LoadedScripts = context.LoadedScripts, References = context.References, Code = code }; }
protected virtual FilePreProcessorResult Parse(Action <FilePreProcessorContext> parseAction) { Guard.AgainstNullArgument("parseAction", parseAction); var context = new FilePreProcessorContext(); _logger.DebugFormat("Starting pre-processing"); parseAction(context); var code = GenerateCode(context); _logger.DebugFormat("Pre-processing finished successfully"); return(new FilePreProcessorResult { UsingStatements = context.UsingStatements, LoadedScripts = context.LoadedScripts, References = context.References, Code = code }); }
protected virtual void ParseScript(List <string> scriptLines, FilePreProcessorContext context, string path = null) { Guard.AgainstNullArgument("scriptLines", scriptLines); Guard.AgainstNullArgument("context", context); // Insert line directive if there's a path if (path != null) { InsertLineDirective(path, scriptLines); } var codeIndex = scriptLines.FindIndex(PreProcessorUtil.IsNonDirectiveLine); for (var index = 0; index < scriptLines.Count; index++) { ProcessLine(context, scriptLines[index], index < codeIndex || codeIndex < 0); } if (path != null) { context.LoadedScripts.Add(path); } }
protected virtual void ParseFile(string path, FilePreProcessorContext context) { _logger.DebugFormat("Processing {0}...", Path.GetFileName(path)); var scriptLines = _fileSystem.ReadFileLines(path).ToList(); ParseScript(scriptLines, context, path); }
protected virtual void ProcessLine(FilePreProcessorContext context, string line, bool isBeforeCode) { Guard.AgainstNullArgument("context", context); if (PreProcessorUtil.IsUsingLine(line)) { var @using = PreProcessorUtil.GetPath(PreProcessorUtil.UsingString, line); if (!context.UsingStatements.Contains(@using)) { context.UsingStatements.Add(@using); } return; } if (PreProcessorUtil.IsRLine(line)) { if (isBeforeCode) { var reference = PreProcessorUtil.GetPath(PreProcessorUtil.RString, line); if (!string.IsNullOrWhiteSpace(reference) && !context.References.Contains(reference)) { context.References.Add(reference); } } return; } if (PreProcessorUtil.IsLoadLine(line)) { if (isBeforeCode) { var filePath = PreProcessorUtil.GetPath(PreProcessorUtil.LoadString, line); if (!string.IsNullOrWhiteSpace(filePath) && !context.LoadedScripts.Contains(filePath)) { ParseFile(filePath, context); } } return; } // If we've reached this, the line is part of the body... context.Body.Add(line); }
protected virtual void ParseScript(List<string> scriptLines, FilePreProcessorContext context, string path = null) { Guard.AgainstNullArgument("scriptLines", scriptLines); Guard.AgainstNullArgument("context", context); // Insert line directive if there's a path if (path != null) InsertLineDirective(path, scriptLines); var codeIndex = scriptLines.FindIndex(PreProcessorUtil.IsNonDirectiveLine); for (var index = 0; index < scriptLines.Count; index++) { ProcessLine(context, scriptLines[index], index < codeIndex || codeIndex < 0); } if (path != null) context.LoadedScripts.Add(path); }
private void ParseScript(List<string> scriptLines, FilePreProcessorContext context, string path = null) { // Insert line directive if there's a path if (path != null) InsertLineDirective(path, scriptLines); var codeIndex = scriptLines.FindIndex(PreProcessorUtil.IsNonDirectiveLine); for (var index = 0; index < scriptLines.Count; index++) { ProcessLine(context, scriptLines[index], index < codeIndex || codeIndex < 0); } if (path != null) context.LoadedScripts.Add(path); }