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


C# ICharStream.Seek方法代码示例

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


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

示例1: Execute

 /// <summary>
 /// Execute the actions encapsulated by this executor within the context of a
 /// particular
 /// <see cref="Antlr4.Runtime.Lexer"/>
 /// .
 /// <p>This method calls
 /// <see cref="Antlr4.Runtime.IIntStream.Seek(int)"/>
 /// to set the position of the
 /// <code>input</code>
 /// 
 /// <see cref="Antlr4.Runtime.ICharStream"/>
 /// prior to calling
 /// <see cref="ILexerAction.Execute(Antlr4.Runtime.Lexer)"/>
 /// on a position-dependent action. Before the
 /// method returns, the input position will be restored to the same position
 /// it was in when the method was invoked.</p>
 /// </summary>
 /// <param name="lexer">The lexer instance.</param>
 /// <param name="input">
 /// The input stream which is the source for the current token.
 /// When this method is called, the current
 /// <see cref="Antlr4.Runtime.IIntStream.Index()"/>
 /// for
 /// <code>input</code>
 /// should be the start of the following token, i.e. 1
 /// character past the end of the current token.
 /// </param>
 /// <param name="startIndex">
 /// The token start index. This value may be passed to
 /// <see cref="Antlr4.Runtime.IIntStream.Seek(int)"/>
 /// to set the
 /// <code>input</code>
 /// position to the beginning
 /// of the token.
 /// </param>
 public virtual void Execute(Lexer lexer, ICharStream input, int startIndex)
 {
     bool requiresSeek = false;
     int stopIndex = input.Index;
     try
     {
         foreach (ILexerAction lexerAction in lexerActions)
         {
             ILexerAction action = lexerAction;
             if (action is LexerIndexedCustomAction)
             {
                 int offset = ((LexerIndexedCustomAction)action).Offset;
                 input.Seek(startIndex + offset);
                 action = ((LexerIndexedCustomAction)action).Action;
                 requiresSeek = (startIndex + offset) != stopIndex;
             }
             else
             {
                 if (action.IsPositionDependent)
                 {
                     input.Seek(stopIndex);
                     requiresSeek = false;
                 }
             }
             action.Execute(lexer);
         }
     }
     finally
     {
         if (requiresSeek)
         {
             input.Seek(stopIndex);
         }
     }
 }
开发者ID:rharrisxtheta,项目名称:antlr4cs,代码行数:70,代码来源:LexerActionExecutor.cs

示例2: EvaluatePredicate

 /// <summary>Evaluate a predicate specified in the lexer.</summary>
 /// <remarks>
 /// Evaluate a predicate specified in the lexer.
 /// <p/>
 /// If
 /// <code>speculative</code>
 /// is
 /// <code>true</code>
 /// , this method was called before
 /// <see cref="Consume(Antlr4.Runtime.ICharStream)">Consume(Antlr4.Runtime.ICharStream)
 ///     </see>
 /// for the matched character. This method should call
 /// <see cref="Consume(Antlr4.Runtime.ICharStream)">Consume(Antlr4.Runtime.ICharStream)
 ///     </see>
 /// before evaluating the predicate to ensure position
 /// sensitive values, including
 /// <see cref="Antlr4.Runtime.Lexer.Text()">Antlr4.Runtime.Lexer.Text()</see>
 /// ,
 /// <see cref="Antlr4.Runtime.Lexer.Line()">Antlr4.Runtime.Lexer.Line()</see>
 /// ,
 /// and
 /// <see cref="Antlr4.Runtime.Lexer.Column()">Antlr4.Runtime.Lexer.Column()</see>
 /// , properly reflect the current
 /// lexer state. This method should restore
 /// <code>input</code>
 /// and the simulator
 /// to the original state before returning (i.e. undo the actions made by the
 /// call to
 /// <see cref="Consume(Antlr4.Runtime.ICharStream)">Consume(Antlr4.Runtime.ICharStream)
 ///     </see>
 /// .
 /// </remarks>
 /// <param name="input">The input stream.</param>
 /// <param name="ruleIndex">The rule containing the predicate.</param>
 /// <param name="predIndex">The index of the predicate within the rule.</param>
 /// <param name="speculative">
 /// 
 /// <code>true</code>
 /// if the current index in
 /// <code>input</code>
 /// is
 /// one character before the predicate's location.
 /// </param>
 /// <returns>
 /// 
 /// <code>true</code>
 /// if the specified predicate evaluates to
 /// <code>true</code>
 /// .
 /// </returns>
 protected internal virtual bool EvaluatePredicate(ICharStream input, int ruleIndex
     , int predIndex, bool speculative)
 {
     // assume true if no recognizer was provided
     if (recog == null)
     {
         return true;
     }
     if (!speculative)
     {
         return recog.Sempred(null, ruleIndex, predIndex);
     }
     int savedCharPositionInLine = charPositionInLine;
     int savedLine = line;
     int index = input.Index;
     int marker = input.Mark();
     try
     {
         Consume(input);
         return recog.Sempred(null, ruleIndex, predIndex);
     }
     finally
     {
         charPositionInLine = savedCharPositionInLine;
         line = savedLine;
         input.Seek(index);
         input.Release(marker);
     }
 }
开发者ID:hustsii,项目名称:antlr4cs,代码行数:79,代码来源:LexerATNSimulator.cs

示例3: Accept

 protected internal virtual void Accept(ICharStream input, int ruleIndex, int actionIndex
     , int index, int line, int charPos)
 {
     if (actionIndex >= 0 && recog != null)
     {
         recog.Action(null, ruleIndex, actionIndex);
     }
     // seek to after last char in token
     input.Seek(index);
     this.line = line;
     this.charPositionInLine = charPos;
     if (input.La(1) != IntStreamConstants.Eof)
     {
         Consume(input);
     }
 }
开发者ID:hustsii,项目名称:antlr4cs,代码行数:16,代码来源:LexerATNSimulator.cs

示例4: Accept

 protected internal virtual void Accept(ICharStream input, LexerActionExecutor lexerActionExecutor, int startIndex, int index, int line, int charPos)
 {
     // seek to after last char in token
     input.Seek(index);
     this.line = line;
     this.charPositionInLine = charPos;
     if (lexerActionExecutor != null && recog != null)
     {
         lexerActionExecutor.Execute(recog, input, startIndex);
     }
 }
开发者ID:sharwell,项目名称:antlr4cs,代码行数:11,代码来源:LexerATNSimulator.cs

示例5: Accept

        protected void Accept(ICharStream input, LexerActionExecutor lexerActionExecutor,
							  int startIndex, int index, int line, int charPos)
        {
            if (debug)
            {
                Console.WriteLine("ACTION " + lexerActionExecutor);
            }

            // seek to after last char in token
            input.Seek(index);
            this.thisLine = line;
            this.charPositionInLine = charPos;

            if (lexerActionExecutor != null && recog != null)
            {
                lexerActionExecutor.Execute(recog, input, startIndex);
            }
        }
开发者ID:antlr,项目名称:antlr4,代码行数:18,代码来源:LexerATNSimulator.cs

示例6: InternalCompile

        private ErrorList InternalCompile(ICharStream stream)
        {
            var errors = new ErrorList();
            var lexer = TemplateLexer.Create(stream);
            var tStream = new CommonTokenStream(lexer);
            var parser = new TemplateParser(tStream) {Errors = errors};
            var docResult = parser.document();

            _template = new DynamicMethod(
                string.Format("__template_{0}", Name),
                typeof (void),
                new[] {typeof (VirtualTemplate)},
                typeof (VirtualTemplate),
                true);

            var emit = _template.GetILGenerator();
            var ctx = new Context(emit) {OptimizeLevel = OptimizeLevel};
            var doc = new Document(docResult.Tree);

            try
            {
                var e = doc.Generate(ctx);
                errors.AddRange(e);
                _image = (RunTemplate) _template.CreateDelegate(typeof (RunTemplate));
                Assembly = ctx.Sink.Build();
            }
            catch (Exception e)
            {
                errors.ErrorUnhandledCompileError(e);
            }

            stream.Seek(0);
            Source = stream.ToString();

            return errors;
        }
开发者ID:jeffpanici75,项目名称:FastTemplate,代码行数:36,代码来源:VirtualTemplate.cs


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