当前位置: 首页>>代码示例>>C#>>正文


C# ErrorHandler.AddError方法代码示例

本文整理汇总了C#中ErrorHandler.AddError方法的典型用法代码示例。如果您正苦于以下问题:C# ErrorHandler.AddError方法的具体用法?C# ErrorHandler.AddError怎么用?C# ErrorHandler.AddError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ErrorHandler的用法示例。


在下文中一共展示了ErrorHandler.AddError方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Process

        internal void Process(string fileArg)
		{
            GetNames(fileArg);
            // check for file exists
            OpenSource();
            // parse source file
            if (inputFile != null)
            {
                DateTime start = DateTime.Now;
                try
                {
                    handler = new ErrorHandler();
                    scanner = new QUT.Gplex.Lexer.Scanner(inputFile);
                    parser = new QUT.Gplex.Parser.Parser(scanner);
                    scanner.yyhdlr = handler;
                    parser.Initialize(this, scanner, handler, new OptionParser2(ParseOption));
                    aast = parser.Aast;
                    parser.Parse();
                    // aast.DiagnosticDump();
                    if (verbose) 
                        Status(start);
                    CheckOptions();
                    if (!Errors && !ParseOnly)
                    {	// build NFSA
                        if (ChrClasses) {
                            DateTime t0 = DateTime.Now;
                            partition = new Partition( TargetSymCardinality, this );
                            partition.FindClasses( aast );
                            partition.FixMap();
                            if (verbose)
                                ClassStatus( t0, partition.Length );
                        }
                        else
                            CharRange.Init( TargetSymCardinality );
                        nfsa = new NFSA(this);
                        nfsa.Build(aast);
                        if (!Errors)
                        {	// convert to DFSA
                            dfsa = new DFSA(this);
                            dfsa.Convert(nfsa);
                            if (!Errors)
                            {	// minimize automaton
                                if (minimize)
                                    dfsa.Minimize();
                                if (!Errors && !checkOnly)
                                {   // emit the scanner to output file
                                    TextReader frameRdr = FrameReader();
                                    TextWriter outputWrtr = OutputWriter();
                                    dfsa.EmitScanner(frameRdr, outputWrtr);

                                    if (!embedBuffers)
                                        CopyBufferCode();
                                    // Clean up!
                                    if (frameRdr != null) 
                                        frameRdr.Close();
                                    if (outputWrtr != null) 
                                        outputWrtr.Close();
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    string str = ex.Message;
                    handler.AddError(str, aast.AtStart);
                    throw;
                }
            }
		}
开发者ID:pomma89,项目名称:GardenPoints.T4,代码行数:70,代码来源:TaskState.cs

示例2: Main

        private static int Main( string[] args )
        {
            Stream inputFile = null;

            Grammar grammar = null;
            ErrorHandler handler = new ErrorHandler();
            string inputFileInfo = null;  // Filename plus revision time.
            Lexers.Scanner scanner = null;
            Parser.Parser parser = null;
            Assembly assm = Assembly.GetExecutingAssembly();
            object info = Attribute.GetCustomAttribute( assm, typeof( AssemblyFileVersionAttribute ) );
            versionInfo = ((AssemblyFileVersionAttribute)info).Version;

            try {
                string filename = ProcessOptions( args );

                if (filename == null)
                    return MC_OK;

                try {
                    inputFile = new FileStream( filename, FileMode.Open, FileAccess.Read, FileShare.Read );
                    inputFileInfo = filename + " - " + File.GetLastWriteTime( filename ).ToString();
                }
                catch (IOException x) {
                    string message;
                    inputFile = null;
                    if (x is FileNotFoundException)
                        message = String.Format( CultureInfo.InvariantCulture,
                            "Source file <{0}> not found{1}",
                            filename, Environment.NewLine );
                    else
                        message = String.Format( CultureInfo.InvariantCulture,
                            "Source file <{0}> could not be opened{1}",
                            filename, Environment.NewLine );
                    handler.AddError( 4, message, null ); // aast.AtStart;
                    return MC_FILEERROR;
                }

                scanner = new Lexers.Scanner( inputFile );
                scanner.SetHandler( handler );

                parser = new Parser.Parser( filename, inputFileInfo, scanner, handler );
                //
                // If the parse is successful, then process the grammar.
                // Otherwise just report the errors that have been listed.
                //
                if (parser.Parse()) {
                    grammar = parser.Grammar;

                    if (Terminal.Max > 255)
                        handler.ListError( null, 103, CharacterUtilities.Map( Terminal.Max ), '\'' );

                    LALRGenerator generator = new LALRGenerator( grammar );
                    List<AutomatonState> states = generator.BuildStates();
                    generator.ComputeLookAhead();
                    generator.BuildParseTable();
                    if (!grammar.CheckGrammar( handler ))
                        throw new ArgumentException( "Non-terminating grammar" );
                    //
                    // If the grammar has non-terminating non-terms we cannot
                    // create a diagnostic report as the grammar is incomplete.
                    //
                    if (!handler.Errors) {
                        CodeGenerator code = new CodeGenerator();
                        code.Generate( states, grammar );
                    }

                    bool DoDiagnose = Diagnose && !grammar.HasNonTerminatingNonTerms;
                    if (Report || DoDiagnose) {
                        string htmlName = System.IO.Path.ChangeExtension( filename, ".report.html" );
                        try {
                            System.IO.FileStream htmlFile = new System.IO.FileStream( htmlName, System.IO.FileMode.Create );
                            System.IO.StreamWriter htmlWriter = new System.IO.StreamWriter( htmlFile );
                            Grammar.HtmlHeader( htmlWriter, filename );

                            if (Report && DoDiagnose)
                                grammar.GenerateCompoundReport( htmlWriter, inputFileInfo, states );
                            else if (Report)
                                grammar.GenerateReport( htmlWriter, inputFileInfo, states );

                            Grammar.HtmlTrailer( htmlWriter );

                            if (htmlFile != null) {
                                htmlWriter.Flush();
                                htmlFile.Close();
                            }
                        }
                        catch (System.IO.IOException) {
                            Console.Error.WriteLine( "Cannot create html output file {0}", htmlName );
                        }
                    }
                }
            }
            catch (System.Exception e) {
                if (e is TooManyErrorsException)
                    return MC_TOOMANYERRORS;
                Console.Error.WriteLine( "Unexpected Error {0}", e.Message );

                if (NoThrowOnError) {
                    // report the error, do not let it go into the void
//.........这里部分代码省略.........
开发者ID:deAtog,项目名称:gppg,代码行数:101,代码来源:Main.cs

示例3: OpenSource

 /// <summary>
 /// This method opens the source file.  The file is not disposed in this file.
 /// The mainline code (program.cs) can call MakeListing and/or ErrorReport, for 
 /// which the buffered stream needs to be open so as to interleave error messages 
 /// with the source.
 /// </summary>
 internal void OpenSource()
 {
     try
     {
         inputFile = new FileStream(this.pathName, FileMode.Open, FileAccess.Read, FileShare.Read);
         if (verbose) msgWrtr.WriteLine("GPLEX: opened input file <{0}>", pathName);
         inputInfo = this.pathName + " - " + File.GetLastWriteTime(this.pathName).ToString();
     }
     catch (IOException)
     {
         inputFile = null;
         handler = new ErrorHandler(); // To stop handler.ErrNum faulting!
         string message = String.Format(CultureInfo.InvariantCulture, 
             "Source file <{0}> not found{1}", fileName, Environment.NewLine);
         handler.AddError(message, null); // aast.AtStart;
         throw new ArgumentException(message);
     }
 }
开发者ID:pomma89,项目名称:GardenPoints.T4,代码行数:24,代码来源:TaskState.cs

示例4: AddSemanticError

 protected static void AddSemanticError(ErrorHandler errs, string message, Position pos, ErrorSeverity severity)
 {
     if (pos != null)
     {
         errs.AddError(string.Format("Semantic error on line {0}: {1}", pos.StartLine, message),
             pos, severity);
     }
     else
     {
         errs.AddError(string.Format("Semantic error: {0}", message), null, severity);
     }
 }
开发者ID:jonorossi,项目名称:cvsi,代码行数:12,代码来源:AstNode.cs


注:本文中的ErrorHandler.AddError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。