Antlr4.Runtime.Atn.LexerActionExecutor.Execute C# (CSharp) Méthode

Execute() public méthode

Execute the actions encapsulated by this executor within the context of a particular Antlr4.Runtime.Lexer .

This method calls Antlr4.Runtime.IIntStream.Seek(int) to set the position of the input Antlr4.Runtime.ICharStream prior to calling 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.

public Execute ( Lexer lexer, ICharStream input, int startIndex ) : void
lexer Lexer The lexer instance.
input ICharStream /// The input stream which is the source for the current token. /// When this method is called, the current /// /// for /// /// should be the start of the following token, i.e. 1 /// character past the end of the current token. ///
startIndex int /// The token start index. This value may be passed to /// /// to set the /// /// position to the beginning /// of the token. ///
Résultat void
        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);
                }
            }
        }

Usage Example

Exemple #1
0
 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);
     }
 }
All Usage Examples Of Antlr4.Runtime.Atn.LexerActionExecutor::Execute