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


C# Antlr4.Consume方法代码示例

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


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

示例1: Recover

        /// <summary>
        /// When the parser encounters an invalid token before the end of the rule :
        /// consume all tokens until a PeriodSeparator, the end of the line, or the next compiler directive / statement starting keyword.
        /// </summary>
        public override void Recover(Antlr4.Runtime.Parser recognizer, RecognitionException e)
        {
            if (lastErrorIndex == ((ITokenStream)recognizer.InputStream).Index && lastErrorStates != null && lastErrorStates.Contains(recognizer.State))
            {
                // uh oh, another error at same token index and previously-visited
                // state in ATN; must be a case where LT(1) is in the recovery
                // token set so nothing got consumed. Consume a single token
                // at least to prevent an infinite loop; this is a failsafe.
                recognizer.Consume();
            }
            lastErrorIndex = ((ITokenStream)recognizer.InputStream).Index;
            if (lastErrorStates == null)
            {
                lastErrorStates = new IntervalSet();
            }
            lastErrorStates.Add(recognizer.State);

            // Consume until next compiler directive / statement starting keyword (excluded), PeriodSeparator (included), or the end of line
            Token lastConsumedToken = (Token)((ITokenStream)recognizer.InputStream).Lt(-1);
            Token currentInvalidToken = (Token)((ITokenStream)recognizer.InputStream).Lt(1);
            while ((lastConsumedToken == null || currentInvalidToken.TokensLine == lastConsumedToken.TokensLine) && currentInvalidToken.Type != TokenConstants.Eof)
            {
                if (((Token)currentInvalidToken).TokenFamily == TokenFamily.CompilerDirectiveStartingKeyword || ((Token)currentInvalidToken).TokenFamily == TokenFamily.StatementStartingKeyword ||
                    ((Token)currentInvalidToken).TokenFamily == TokenFamily.StatementEndingKeyword || ((Token)currentInvalidToken).TokenFamily == TokenFamily.CodeElementStartingKeyword)
                {
                    break;
                }
                recognizer.Consume();
                if (currentInvalidToken.Type == (int)TokenType.PeriodSeparator)
                {
                    break;
                }
                currentInvalidToken = (Token)((ITokenStream)recognizer.InputStream).Lt(1);
            }
        }
开发者ID:osmedile,项目名称:TypeCobol,代码行数:39,代码来源:CompilerDirectiveErrorStrategy.cs

示例2: RecoverInline

 /// <summary>
 /// When parsing a compiler directive, single token deletion should never
 /// eat the statement starting keyword 
 /// </summary>
 public override IToken RecoverInline(Antlr4.Runtime.Parser recognizer)
 {
     // SINGLE TOKEN DELETION
     Token nextToken = (Token)((ITokenStream)recognizer.InputStream).Lt(1);
     if (nextToken.TokenFamily != TokenFamily.StatementStartingKeyword &&
         nextToken.TokenFamily != TokenFamily.StatementEndingKeyword &&
         nextToken.TokenFamily != TokenFamily.CodeElementStartingKeyword)
     {
         IToken matchedSymbol = SingleTokenDeletion(recognizer);
         if (matchedSymbol != null)
         {
             // we have deleted the extra token.
             // now, move past ttype token as if all were ok
             recognizer.Consume();
             return matchedSymbol;
         }
     }
     // SINGLE TOKEN INSERTION
     if (SingleTokenInsertion(recognizer))
     {
         return GetMissingSymbol(recognizer);
     }
     // even that didn't work; must throw the exception
     throw new InputMismatchException(recognizer);
 }
开发者ID:osmedile,项目名称:TypeCobol,代码行数:29,代码来源:CobolErrorStrategy.cs


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