private static BuildResult <Parser <IN, OUT> > CheckAlternates(BuildResult <Parser <IN, OUT> > result, NonTerminal <IN> nonTerminal) { var conf = result.Result.Configuration; foreach (var rule in nonTerminal.Rules) { foreach (var clause in rule.Clauses) { if (clause is ChoiceClause <IN> choice) { if (!choice.IsTerminalChoice && !choice.IsNonTerminalChoice) { result.AddError(new ParserInitializationError(ErrorLevel.ERROR, $"{rule.RuleString} contains {choice.ToString()} with mixed terminal and nonterminal.", ErrorCodes.PARSER_MIXED_CHOICES)); } else if (choice.IsDiscarded && choice.IsNonTerminalChoice) { result.AddError(new ParserInitializationError(ErrorLevel.ERROR, $"{rule.RuleString} : {choice.ToString()} can not be marked as discarded as it is a non terminal choice.", ErrorCodes.PARSER_NON_TERMINAL_CHOICE_CANNOT_BE_DISCARDED)); } } } } return(result); }
public static BuildResult CompileXibFiles (IProgressMonitor monitor, IEnumerable<ProjectFile> files, FilePath outputRoot) { var result = new BuildResult (); var ibfiles = GetIBFilePairs (files, outputRoot).Where (NeedsBuilding).ToList (); if (ibfiles.Count > 0) { monitor.BeginTask (GettextCatalog.GetString ("Compiling interface definitions"), 0); foreach (var file in ibfiles) { file.EnsureOutputDirectory (); var psi = new ProcessStartInfo ("ibtool", String.Format ("\"{0}\" --compile \"{1}\"", file.Input, file.Output) ); monitor.Log.WriteLine (psi.FileName + " " + psi.Arguments); psi.WorkingDirectory = outputRoot; string errorOutput; int code; try { code = ExecuteCommand (monitor, psi, out errorOutput); } catch (System.ComponentModel.Win32Exception ex) { LoggingService.LogError ("Error running ibtool", ex); result.AddError (null, 0, 0, null, "ibtool not found. Please ensure the Apple SDK is installed."); return result; } if (code != 0) { //FIXME: parse the plist that ibtool returns result.AddError (null, 0, 0, null, "ibtool returned error code " + code); } } monitor.EndTask (); } return result; }
public override BuildResult <Parser <IN, OUT> > BuildParser(object parserInstance, ParserType parserType, string rootRule, BuildExtension <IN> extensionBuilder = null) { var ruleparser = new RuleParser <IN>(); var builder = new ParserBuilder <EbnfTokenGeneric, GrammarNode <IN> >(); var grammarParser = builder.BuildParser(ruleparser, ParserType.LL_RECURSIVE_DESCENT, "rule").Result; var result = new BuildResult <Parser <IN, OUT> >(); ParserConfiguration <IN, OUT> configuration = null; try { configuration = ExtractEbnfParserConfiguration(parserInstance.GetType(), grammarParser); configuration.StartingRule = rootRule; } catch (Exception e) { result.AddError(new ParserInitializationError(ErrorLevel.ERROR, e.Message, ErrorCodes.PARSER_UNKNOWN_ERROR)); return(result); } var syntaxParser = BuildSyntaxParser(configuration, parserType, rootRule); SyntaxTreeVisitor <IN, OUT> visitor = null; if (parserType == ParserType.LL_RECURSIVE_DESCENT) { new SyntaxTreeVisitor <IN, OUT>(configuration, parserInstance); } else if (parserType == ParserType.EBNF_LL_RECURSIVE_DESCENT) { visitor = new EBNFSyntaxTreeVisitor <IN, OUT>(configuration, parserInstance); } var parser = new Parser <IN, OUT>(syntaxParser, visitor); parser.Configuration = configuration; var lexerResult = BuildLexer(extensionBuilder); if (lexerResult.IsError) { foreach (var lexerResultError in lexerResult.Errors) { result.AddError(lexerResultError); } return(result); } else { parser.Lexer = lexerResult.Result; } parser.Instance = parserInstance; result.Result = parser; return(result); }
bool CompileResourceScript(BuildResult targetBuildResult, ProjectFile f) { var res = GetRelativeObjectFileName(ObjectDirectory, f, ".res"); // Build argument string var resCmpArgs = FillInMacros(Win32ResourceCompiler.Instance.Arguments, new Win32ResourceCompiler.ArgProvider { RcFile = f.FilePath, ResFile = res }, commonMacros); // Execute compiler string output; string stdOutput; int _exitCode = ExecuteCommand(Win32ResourceCompiler.Instance.Executable, resCmpArgs, Project.BaseDirectory, monitor, out output, out stdOutput); // Error analysis if (!string.IsNullOrEmpty(output)) { targetBuildResult.AddError(f.FilePath, 0, 0, "", output); } if (!string.IsNullOrEmpty(stdOutput)) { targetBuildResult.AddError(f.FilePath, 0, 0, "", stdOutput); } ErrorExtracting.HandleReturnCode(monitor, targetBuildResult, _exitCode); if (_exitCode != 0) { targetBuildResult.FailedBuildCount++; return(false); } else { f.LastGenOutput = res; targetBuildResult.BuildCount++; Project.LastModificationTimes [f] = File.GetLastWriteTime(f.FilePath); BuiltObjects.Add(MakeRelativeToPrjBase(res)); return(true); } }
BuildResult Respack(IProgressMonitor monitor, MoonlightProject proj, List <FilePath> toResGen, FilePath outfile) { monitor.Log.WriteLine("Packing resources..."); var runtime = proj.TargetRuntime; BuildResult result = new BuildResult(); string respack = runtime.GetToolPath(proj.TargetFramework, "respack"); if (String.IsNullOrEmpty(respack)) { result.AddError(null, 0, 0, null, "Could not find respack"); result.FailedBuildCount++; return(result); } var si = new System.Diagnostics.ProcessStartInfo(); var env = runtime.GetToolsExecutionEnvironment(proj.TargetFramework); env.MergeTo(si); si.FileName = respack.EndsWith(".exe")? "mono" : respack; si.WorkingDirectory = outfile.ParentDirectory; var sb = new System.Text.StringBuilder(); if (respack.EndsWith(".exe")) { sb.Append(respack); sb.Append(" "); } sb.Append(outfile); foreach (var infile in toResGen) { sb.AppendFormat(" \"{0}\",\"{1}\"", infile.FullPath, infile.ToRelative(proj.BaseDirectory)); } si.Arguments = sb.ToString(); string err; int exit = ExecuteCommand(monitor, si, out err); if (exit != 0) { result.AddError(null, 0, 0, exit.ToString(), "respack failed: " + err); result.FailedBuildCount++; } return(result); }
public BuildResult Build(IProgressMonitor monitor, ConfigurationSelector configuration) { BuildResult results = new BuildResult("", 0, 0); string moFileName = GetOutFile(configuration); string moDirectory = Path.GetDirectoryName(moFileName); if (!Directory.Exists(moDirectory)) { Directory.CreateDirectory(moDirectory); } var pb = new ProcessArgumentBuilder(); pb.AddQuoted(PoFile); pb.Add("-o"); pb.AddQuoted(moFileName); ProcessWrapper process = null; try { process = Runtime.ProcessService.StartProcess(GetTool("msgfmt"), pb.ToString(), parentProject.BaseDirectory, monitor.Log, monitor.Log, null); } catch (System.ComponentModel.Win32Exception) { var msg = GettextCatalog.GetString("Did not find msgfmt. Please ensure that gettext tools are installed."); monitor.ReportError(msg, null); results.AddError(msg); return(results); } process.WaitForOutput(); if (process.ExitCode == 0) { monitor.Log.WriteLine(GettextCatalog.GetString("Translation {0}: Compilation succeeded.", IsoCode)); } else { string message = GettextCatalog.GetString("Translation {0}: Compilation failed. See log for details.", IsoCode); monitor.Log.WriteLine(message); results.AddError(PoFile, 1, 1, "", message); results.FailedBuildCount = 1; } return(results); }
public static BuildResult CreateMergedPlist(IProgressMonitor monitor, ProjectFile template, string outPath, Func <PlistDocument, BuildResult> merge) { var result = new BuildResult(); var doc = new PlistDocument(); if (template != null) { try { doc.LoadFromXmlFile(template.FilePath); } catch (Exception ex) { if (ex is XmlException) { result.AddError(template.FilePath, ((XmlException)ex).LineNumber, ((XmlException)ex).LinePosition, null, ex.Message); } else { result.AddError(template.FilePath, 0, 0, null, ex.Message); } monitor.ReportError(GettextCatalog.GetString("Could not load file '{0}': {1}", template.FilePath, ex.Message), null); return(result); } } try { if (result.Append(merge(doc)).ErrorCount > 0) { return(result); } } catch (Exception ex) { result.AddError("Error merging Info.plist: " + ex.Message); LoggingService.LogError("Error merging Info.plist", ex); return(result); } try { EnsureDirectoryForFile(outPath); doc.WriteToFile(outPath); } catch (Exception ex) { result.AddError(outPath, 0, 0, null, ex.Message); monitor.ReportError(GettextCatalog.GetString("Could not write file '{0}'", outPath), ex); } return(result); }
private static BuildResult <Parser <IN, OUT> > CheckUnreachable(BuildResult <Parser <IN, OUT> > result, NonTerminal <IN> nonTerminal) { var conf = result.Result.Configuration; var found = false; if (nonTerminal.Name != conf.StartingRule) { foreach (var nt in result.Result.Configuration.NonTerminals.Values.ToList()) { if (nt.Name != nonTerminal.Name) { found = NonTerminalReferences(nt, nonTerminal.Name); if (found) { break; } } } if (!found) { result.AddError(new ParserInitializationError(ErrorLevel.WARN, $"non terminal [{nonTerminal.Name}] is never used.")); } } return(result); }
private static BuildResult <ILexer <IN> > Build <IN>(Dictionary <IN, List <LexemeAttribute> > attributes, BuildResult <ILexer <IN> > result, BuildExtension <IN> extensionBuilder = null) where IN : struct { var hasRegexLexem = IsRegexLexer(attributes); var hasGenericLexem = IsGenericLexer(attributes); if (hasGenericLexem && hasRegexLexem) { result.AddError(new LexerInitializationError(ErrorLevel.WARN, "cannot mix Regex lexemes and Generic lexemes in same lexer")); result.IsError = true; } else { if (hasRegexLexem) { result = BuildRegexLexer(attributes, result); } else if (hasGenericLexem) { result = BuildGenericLexer(attributes, extensionBuilder, result); } } return(result); }
public static BuildResult UpdateCodeBehind (IProgressMonitor monitor, XibCodeBehind generator, IEnumerable<ProjectFile> items) { var result = new BuildResult (); var writer = MonoDevelop.DesignerSupport.CodeBehindWriter.CreateForProject (monitor, generator.Project); if (!writer.SupportsPartialTypes) { monitor.ReportWarning ("Cannot generate designer code, because CodeDom " + "provider does not support partial classes."); return result; } var files = generator.GetDesignerFilesNeedBuilding (items, false).ToList (); if (files.Count == 0) return result; monitor.BeginTask (GettextCatalog.GetString ("Updating CodeBehind files"), 0); foreach (var f in files) { try { generator.GenerateDesignerCode (writer, f.Key, f.Value); var relPath = f.Value.FilePath.ToRelative (generator.Project.BaseDirectory); monitor.Log.WriteLine (GettextCatalog.GetString ("Updated {0}", relPath)); } catch (Exception ex) { result = result ?? new BuildResult (); result.AddError (f.Key.FilePath, 0, 0, null, ex.Message); LoggingService.LogError (String.Format ("Error generating code for xib file '{0}'", f.Key.FilePath), ex); } } writer.WriteOpenFiles (); monitor.EndTask (); return result; }
BuildResult CreateDnxRuntimeErrorBuildResult() { var buildResult = new BuildResult(); buildResult.AddError(DnxServices.ProjectService.CurrentRuntimeError); return(buildResult); }
public static BuildResult UpdateDesignerFile( CodeBehindWriter writer, AspNetAppProject project, ProjectFile file, ProjectFile designerFile ) { var result = new BuildResult(); //parse the ASP.NET file var parsedDocument = TypeSystemService.ParseFile(project, file.FilePath) as AspNetParsedDocument; if (parsedDocument == null) { result.AddError(string.Format("Failed to parse file '{0}'", file.Name)); return(result); } //TODO: ensure type system is up to date CodeCompileUnit ccu; result.Append(GenerateCodeBehind(project, designerFile.FilePath, parsedDocument, out ccu)); if (ccu != null) { writer.WriteFile(designerFile.FilePath, ccu); } return(result); }
protected override Task <BuildResult> OnBuild(ProgressMonitor monitor, ConfigurationSelector configuration, OperationContext operationContext) { return(Task.Factory.StartNew(() => { BuildResult results; if (!CheckCMake()) { results = new BuildResult(); results.AddError("CMake cannot be found."); return results; } FileService.CreateDirectory(file.ParentDirectory.Combine(outputDirectory)); monitor.BeginStep("Generating build files."); Stream generationResult = ExecuteCommand("cmake", "../", outputDirectory, monitor); results = ParseGenerationResult(generationResult, monitor); monitor.EndStep(); monitor.BeginStep("Building..."); Stream buildResult = ExecuteCommand("cmake", "--build ./ --clean-first", outputDirectory, monitor); //TODO: Parse results. monitor.EndStep(); return results; })); }
static BuildResult BuildError(string error) { var br = new BuildResult(); br.AddError(error); return(br); }
public BuildResult Build(IProgressMonitor monitor, ConfigurationSelector configuration) { BuildResult results = new BuildResult("", 0, 0); string moFileName = GetOutFile(configuration); string moDirectory = Path.GetDirectoryName(moFileName); if (!Directory.Exists(moDirectory)) { Directory.CreateDirectory(moDirectory); } ProcessWrapper process = Runtime.ProcessService.StartProcess("msgfmt", "\"" + PoFile + "\" -o \"" + moFileName + "\"", parentProject.BaseDirectory, monitor.Log, monitor.Log, null); process.WaitForOutput(); if (process.ExitCode == 0) { monitor.Log.WriteLine(GettextCatalog.GetString("Translation {0}: Compilation succeeded.", IsoCode)); } else { string error = process.StandardError.ReadToEnd(); string message = String.Format(GettextCatalog.GetString("Translation {0}: Compilation failed. Reason: {1}"), IsoCode, error); monitor.Log.WriteLine(message); results.AddError(PoFile, 1, 1, "", message); results.FailedBuildCount = 1; } return(results); }
/// <summary> /// Compiles a D project. /// </summary> public BuildResult Build(DProject Project, ConfigurationSelector BuildConfigurationSelector) { this.Project = Project; BuildConfig = Project.GetConfiguration(BuildConfigurationSelector) as DProjectConfiguration; commonMacros = new PrjPathMacroProvider { slnPath = Project.ParentSolution != null?EnsureCorrectPathSeparators(Project.ParentSolution.BaseDirectory) : "" }; BuiltObjects.Clear(); if (Compiler == null) { var targetBuildResult = new BuildResult(); targetBuildResult.AddError("Project compiler \"" + Project.UsedCompilerVendor + "\" not found"); targetBuildResult.FailedBuildCount++; return(targetBuildResult); } if (!Directory.Exists(AbsoluteObjectDirectory)) { Directory.CreateDirectory(AbsoluteObjectDirectory); } if (CanDoOneStepBuild) { return(DoOneStepBuild()); } else { return(DoStepByStepBuild()); } }
public static BuildResult UpdateDesignerFile( CodeBehindWriter writer, DotNetProject project, ProjectFile file, ProjectFile designerFile ) { var result = new BuildResult(); //parse the ASP.NET file if (!(IdeApp.TypeSystemService.ParseFile(project, file.FilePath).Result is WebFormsParsedDocument parsedDocument)) { result.AddError(GettextCatalog.GetString("Failed to parse file '{0}'", file.Name)); return(result); } //TODO: ensure type system is up to date CodeCompileUnit ccu; result.Append(GenerateCodeBehind(project, designerFile.FilePath, parsedDocument, out ccu)); if (ccu != null) { writer.WriteFile(designerFile.FilePath, ccu); } return(result); }
private static BuildResult <ILexer <IN> > Build <IN>(Dictionary <IN, List <LexemeAttribute> > attributes, BuildResult <ILexer <IN> > result, BuildExtension <IN> extensionBuilder = null) where IN : struct { var hasRegexLexemes = IsRegexLexer(attributes); var hasGenericLexemes = IsGenericLexer(attributes); if (hasGenericLexemes && hasRegexLexemes) { result.AddError(new LexerInitializationError(ErrorLevel.ERROR, "cannot mix Regex lexemes and Generic lexemes in same lexer", ErrorCodes.LEXER_CANNOT_MIX_GENERIC_AND_REGEX)); } else { if (hasRegexLexemes) { result = BuildRegexLexer(attributes, result); } else if (hasGenericLexemes) { result = BuildGenericLexer(attributes, extensionBuilder, result); } } return(result); }
protected override BuildResult Build(IProgressMonitor monitor, IBuildTarget item, ConfigurationSelector configuration) { if (!(item is MonoDroidProject)) { return(base.Build(monitor, item, configuration)); } MonoDroidProject project = (MonoDroidProject)item; TargetFramework requiredFramework = Runtime.SystemAssemblyService.GetTargetFramework( MonoDevelop.Core.Assemblies.TargetFrameworkMoniker.NET_4_0); // Check that we support 4.0 to infer we are at Mono 2.8 at least. if (!project.TargetRuntime.IsInstalled(requiredFramework)) { var message = "Mono 2.8 or newer is required."; MessageService.GenericAlert(MonoDevelop.Ide.Gui.Stock.MonoDevelop, message, "Mono 2.8 or newer is requiered. Please go to http://www.mono-project.com to update your installation.", AlertButton.Ok); var buildResult = new BuildResult(); buildResult.AddError(message); return(buildResult); } return(base.Build(monitor, item, configuration)); }
public static Dictionary <IN, List <LexemeAttribute> > GetLexemes <IN>(BuildResult <ILexer <IN> > result) { var values = Enum.GetValues(typeof(IN)); var attributes = new Dictionary <IN, List <LexemeAttribute> >(); var fields = typeof(IN).GetFields(); foreach (Enum value in values) { var tokenID = (IN)(object)value; var enumattributes = value.GetAttributesOfType <LexemeAttribute>(); if (enumattributes == null || enumattributes.Count == 0) { result?.AddError(new LexerInitializationError(ErrorLevel.WARN, $"token {tokenID} in lexer definition {typeof(IN).FullName} does not have Lexeme")); } else { foreach (var lexem in enumattributes) { if (lexem != null) { var lex = new List <LexemeAttribute>(); if (attributes.ContainsKey(tokenID)) { lex = attributes[tokenID]; } lex.Add(lexem); attributes[tokenID] = lex; } else { if (!tokenID.Equals(default(IN))) { result?.AddError(new LexerInitializationError(ErrorLevel.WARN, $"token {tokenID} in lexer definition {typeof(IN).FullName} does not have Lexeme")); } } } } ; } return(attributes); }
public override void LogImportantMessage(string message, params object[] messageArgs) { monitor.Log.WriteLine(string.Format(message, messageArgs)); if (result != null) { result.AddError(string.Format(message, messageArgs)); } }
BuildResult CreateBuildError(string message) { var result = new BuildResult(); result.SourceTarget = Project; result.AddError(message); return(result); }
public static BuildResult Compile(NMEProject project, NMEProjectConfiguration configuration, IProgressMonitor monitor) { string args = "run nme build \"" + project.TargetNMMLFile + "\" " + configuration.Platform.ToLower(); if (configuration.DebugMode) { args += " -debug"; } if (project.AdditionalArguments != "") { args += " " + project.AdditionalArguments; } if (configuration.AdditionalArguments != "") { args += " " + configuration.AdditionalArguments; } string error = ""; int exitCode = DoCompilation("haxelib", args, project.BaseDirectory, monitor, ref error); BuildResult result = ParseOutput(project, error); if (result.CompilerOutput.Trim().Length != 0) { monitor.Log.WriteLine(result.CompilerOutput); } if (result.ErrorCount == 0 && exitCode != 0) { string errorMessage = File.ReadAllText(error); if (!string.IsNullOrEmpty(errorMessage)) { result.AddError(errorMessage); } else { result.AddError("Build failed. Go to \"Build Output\" for more information"); } } FileService.DeleteFile(error); return(result); }
public static BuildResult CompileXibFiles(IProgressMonitor monitor, IEnumerable <ProjectFile> files, FilePath outputRoot) { var result = new BuildResult(); var ibfiles = GetIBFilePairs(files, outputRoot).Where(NeedsBuilding).ToList(); if (ibfiles.Count > 0) { monitor.BeginTask(GettextCatalog.GetString("Compiling interface definitions"), 0); foreach (var file in ibfiles) { file.EnsureOutputDirectory(); var args = new ProcessArgumentBuilder(); args.Add("--errors", "--warnings", "--notices", "--output-format", "human-readable-text"); args.AddQuoted(file.Input); args.Add("--compile"); args.AddQuoted(file.Output); var ibtoolPath = AppleSdkSettings.DeveloperRoot.Combine("usr", "bin", "ibtool"); var psi = new ProcessStartInfo(ibtoolPath, args.ToString()); monitor.Log.WriteLine(psi.FileName + " " + psi.Arguments); int code; try { code = MacBuildUtilities.ExecuteBuildCommand(monitor, psi); } catch (System.ComponentModel.Win32Exception ex) { LoggingService.LogError("Error running ibtool", ex); result.AddError(null, 0, 0, null, "ibtool not found. Please ensure the Apple SDK is installed."); return(result); } if (monitor.IsCancelRequested) { return(result); } if (code != 0) { result.AddError(null, 0, 0, null, "ibtool returned error code " + code); return(result); } } monitor.EndTask(); } return(result); }
private static BuildResult <ILexer <IN> > BuildRegexLexer <IN>(Dictionary <IN, List <LexemeAttribute> > attributes, BuildResult <ILexer <IN> > result) where IN : struct { ILexer <IN> lexer = new Lexer <IN>(); foreach (var pair in attributes) { var tokenID = pair.Key; var lexems = pair.Value; if (lexems != null) { try { foreach (var lexem in lexems) { lexer.AddDefinition(new TokenDefinition <IN>(tokenID, lexem.Pattern, lexem.IsSkippable, lexem.IsLineEnding)); } } catch (Exception e) { result.AddError(new LexerInitializationError(ErrorLevel.ERROR, $"error at lexem {tokenID} : {e.Message}")); } } else { if (!tokenID.Equals(default(IN))) { result.AddError(new LexerInitializationError(ErrorLevel.WARN, $"token {tokenID} in lexer definition {typeof(IN).FullName} does not have")); } } ; } result.Result = lexer; return(result); }
private static Dictionary <IN, List <CommentAttribute> > GetCommentsAttribute <IN>(BuildResult <ILexer <IN> > result) where IN : struct { var attributes = new Dictionary <IN, List <CommentAttribute> >(); var values = Enum.GetValues(typeof(IN)); foreach (Enum value in values) { var tokenID = (IN)(object)value; var enumAttributes = value.GetAttributesOfType <CommentAttribute>(); if (enumAttributes != null && enumAttributes.Any()) { attributes[tokenID] = enumAttributes.ToList(); } } var commentCount = attributes.Values.Select(l => l?.Count(attr => attr.GetType() == typeof(CommentAttribute)) ?? 0).Sum(); var multiLineCommentCount = attributes.Values.Select(l => l?.Count(attr => attr.GetType() == typeof(MultiLineCommentAttribute)) ?? 0).Sum(); var singleLineCommentCount = attributes.Values.Select(l => l?.Count(attr => attr.GetType() == typeof(SingleLineCommentAttribute)) ?? 0).Sum(); if (commentCount > 1) { result.AddError(new LexerInitializationError(ErrorLevel.FATAL, "too many comment lexem")); } if (multiLineCommentCount > 1) { result.AddError(new LexerInitializationError(ErrorLevel.FATAL, "too many multi-line comment lexem")); } if (singleLineCommentCount > 1) { result.AddError(new LexerInitializationError(ErrorLevel.FATAL, "too many single-line comment lexem")); } if (commentCount > 0 && (multiLineCommentCount > 0 || singleLineCommentCount > 0)) { result.AddError(new LexerInitializationError(ErrorLevel.FATAL, "comment lexem can't be used together with single-line or multi-line comment lexems")); } return(attributes); }
async Task <BuildResult> WaitForRestoreThenBuild(Task restoreTask, ProgressMonitor monitor, ConfigurationSelector configuration, OperationContext operationContext) { try { await restoreTask; } catch (Exception ex) { var result = new BuildResult(); result.AddError(GettextCatalog.GetString("{0}. Please see the Package Console for more details.", ex.Message)); return(result); } return(await base.OnBuild(monitor, configuration, operationContext)); }
private static BuildResult <Parser <IN, OUT> > CheckArgType(BuildResult <Parser <IN, OUT> > result, Rule <IN> rule, Type expected, MethodInfo visitor, ParameterInfo arg) { if (!expected.IsAssignableFrom(arg.ParameterType) && arg.ParameterType != expected) { result.AddError(new InitializationError(ErrorLevel.FATAL, $"visitor {visitor.Name} for rule {rule.RuleString} ; parameter {arg.Name} has incorrect type : expected {expected}, found {arg.ParameterType}", ErrorCodes.PARSER_INCORRECT_VISITOR_PARAMETER_TYPE)); } return(result); }
public override BuildResult <Parser <IN, OUT> > BuildParser(object parserInstance, ParserType parserType, string rootRule) { RuleParser <IN> ruleparser = new RuleParser <IN>(); ParserBuilder <EbnfToken, GrammarNode <IN> > builder = new ParserBuilder <EbnfToken, GrammarNode <IN> >(); Parser <EbnfToken, GrammarNode <IN> > grammarParser = builder.BuildParser(ruleparser, ParserType.LL_RECURSIVE_DESCENT, "rule").Result; BuildResult <Parser <IN, OUT> > result = new BuildResult <Parser <IN, OUT> >(); ParserConfiguration <IN, OUT> configuration = null; try { configuration = ExtractEbnfParserConfiguration(parserInstance.GetType(), grammarParser); configuration.StartingRule = rootRule; } catch (Exception e) { result.AddError(new ParserInitializationError(ErrorLevel.ERROR, e.Message)); return(result); } ISyntaxParser <IN, OUT> syntaxParser = BuildSyntaxParser(configuration, parserType, rootRule); SyntaxTreeVisitor <IN, OUT> visitor = null; if (parserType == ParserType.LL_RECURSIVE_DESCENT) { new SyntaxTreeVisitor <IN, OUT>(configuration, parserInstance); } else if (parserType == ParserType.EBNF_LL_RECURSIVE_DESCENT) { visitor = new EBNFSyntaxTreeVisitor <IN, OUT>(configuration, parserInstance); } Parser <IN, OUT> parser = new Parser <IN, OUT>(syntaxParser, visitor); parser.Configuration = configuration; var lexerResult = BuildLexer(); if (lexerResult.IsError) { result.AddErrors(lexerResult.Errors); } else { parser.Lexer = lexerResult.Result; } parser.Instance = parserInstance; result.Result = parser; return(result); }
/// <summary> /// Checks a compilation return code, /// and adds an error result if the compiler results /// show no errors. /// </summary> /// <param name="returnCode"> /// A <see cref="System.Int32"/>: A process return code /// </param> /// <param name="cr"> /// A <see cref="CompilerResults"/>: The return code from a compilation run /// </param> void HandleReturnCode(BuildResult br, string executable, int returnCode) { if (returnCode != 0) { if (monitor != null) { monitor.Log.WriteLine("Exit code " + returnCode.ToString()); } br.AddError(string.Empty, 0, 0, string.Empty, GettextCatalog.GetString("Build failed - check build output for details")); } }