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


C# ParsingContext.SetSourceLocation方法代码示例

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


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

示例1: TryRecoverFromError

        protected bool TryRecoverFromError(ParsingContext context)
        {
            var grammar = context.Language.Grammar;
              var parser = context.Parser;
              //1. We need to find a state in the stack that has a shift item based on error production (with error token),
              // and error terminal is current. This state would have a shift action on error token.
              ParserAction errorShiftAction = FindErrorShiftActionInStack(context);
              if (errorShiftAction == null) return false; //we failed to recover
              context.AddTrace(Resources.MsgTraceRecoverFoundState, context.CurrentParserState);
              //2. Shift error token - execute shift action
              context.AddTrace(Resources.MsgTraceRecoverShiftError, errorShiftAction);
              errorShiftAction.Execute(context);
              //4. Now we need to go along error production until the end, shifting tokens that CAN be shifted and ignoring others.
              //   We shift until we can reduce
              context.AddTrace(Resources.MsgTraceRecoverShiftTillEnd);
              while (true) {
            if (context.CurrentParserInput == null)
              parser.ReadInput();
            if (context.CurrentParserInput.Term == grammar.Eof)
              return false;
            //Check if we can reduce
            var nextAction = parser.GetNextAction();
            if (nextAction == null) {
              parser.ReadInput();
              continue;
            }
            if (nextAction is ReduceParserAction) {
              //We are reducing a fragment containing error - this is the end of recovery
              //Clear all input token queues and buffered input, reset location back to input position token queues;
              context.SetSourceLocation(context.CurrentParserInput.Span.Location);

              //Reduce error production - it creates parent non-terminal that "hides" error inside
              context.AddTrace(Resources.MsgTraceRecoverReducing);
              context.AddTrace(Resources.MsgTraceRecoverAction, nextAction);
              nextAction.Execute(context); //execute reduce
              return true; //we recovered
            }
            // If it is not reduce, simply execute it (it is most likely shift)
            context.AddTrace(Resources.MsgTraceRecoverAction, nextAction);
            nextAction.Execute(context); //shift input token
              }
        }
开发者ID:dbremner,项目名称:irony,代码行数:42,代码来源:ErrorRecoveryParserAction.cs


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