/// <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 /// <paramref name="input"/> /// /// <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 /// <paramref name="input"/> /// 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 /// <paramref name="input"/> /// 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); } } }
/// <summary> /// <inheritDoc/> /// <p>This method calls /// <see cref="Execute(Antlr4.Runtime.Lexer)"/> /// on the result of /// <see cref="Action()"/> /// using the provided /// <code>lexer</code> /// .</p> /// </summary> public void Execute(Lexer lexer) { // assume the input stream position was properly set by the calling code action.Execute(lexer); }