This implementation of ILexerAction is used for tracking input offsets for position-dependent actions within a LexerActionExecutor .

This action is not serialized as part of the ATN, and is only required for position-dependent lexer actions which appear at a location other than the end of a rule. For more information about DFA optimizations employed for lexer actions, see LexerActionExecutor.Append(LexerActionExecutor, ILexerAction) and LexerActionExecutor.FixOffsetBeforeMatch(int) .

Inheritance: ILexerAction
Exemple #1
0
 public override bool Equals(object obj)
 {
     if (obj == this)
     {
         return(true);
     }
     else
     {
         if (!(obj is Antlr4.Runtime.Atn.LexerIndexedCustomAction))
         {
             return(false);
         }
     }
     Antlr4.Runtime.Atn.LexerIndexedCustomAction other = (Antlr4.Runtime.Atn.LexerIndexedCustomAction)obj;
     return(offset == other.offset && action.Equals(other.action));
 }
Exemple #2
0
 /// <summary>
 /// Creates a
 /// <see cref="LexerActionExecutor"/>
 /// which encodes the current offset
 /// for position-dependent lexer actions.
 /// <p>Normally, when the executor encounters lexer actions where
 /// <see cref="ILexerAction.IsPositionDependent()"/>
 /// returns
 /// <see langword="true"/>
 /// , it calls
 /// <see cref="Antlr4.Runtime.IIntStream.Seek(int)"/>
 /// on the input
 /// <see cref="Antlr4.Runtime.ICharStream"/>
 /// to set the input
 /// position to the <em>end</em> of the current token. This behavior provides
 /// for efficient DFA representation of lexer actions which appear at the end
 /// of a lexer rule, even when the lexer rule matches a variable number of
 /// characters.</p>
 /// <p>Prior to traversing a match transition in the ATN, the current offset
 /// from the token start index is assigned to all position-dependent lexer
 /// actions which have not already been assigned a fixed offset. By storing
 /// the offsets relative to the token start index, the DFA representation of
 /// lexer actions which appear in the middle of tokens remains efficient due
 /// to sharing among tokens of the same length, regardless of their absolute
 /// position in the input stream.</p>
 /// <p>If the current executor already has offsets assigned to all
 /// position-dependent lexer actions, the method returns
 /// <c>this</c>
 /// .</p>
 /// </summary>
 /// <param name="offset">
 /// The current offset to assign to all position-dependent
 /// lexer actions which do not already have offsets assigned.
 /// </param>
 /// <returns>
 /// A
 /// <see cref="LexerActionExecutor"/>
 /// which stores input stream offsets
 /// for all position-dependent lexer actions.
 /// </returns>
 public virtual Antlr4.Runtime.Atn.LexerActionExecutor FixOffsetBeforeMatch(int offset)
 {
     ILexerAction[] updatedLexerActions = null;
     for (int i = 0; i < lexerActions.Length; i++)
     {
         if (lexerActions[i].IsPositionDependent && !(lexerActions[i] is LexerIndexedCustomAction))
         {
             if (updatedLexerActions == null)
             {
                 updatedLexerActions = (ILexerAction[])lexerActions.Clone();
             }
             updatedLexerActions[i] = new LexerIndexedCustomAction(offset, lexerActions[i]);
         }
     }
     if (updatedLexerActions == null)
     {
         return(this);
     }
     return(new Antlr4.Runtime.Atn.LexerActionExecutor(updatedLexerActions));
 }
 /// <summary>
 /// Creates a
 /// <see cref="LexerActionExecutor"/>
 /// which encodes the current offset
 /// for position-dependent lexer actions.
 /// <p>Normally, when the executor encounters lexer actions where
 /// <see cref="ILexerAction.IsPositionDependent()"/>
 /// returns
 /// <code>true</code>
 /// , it calls
 /// <see cref="Antlr4.Runtime.IIntStream.Seek(int)"/>
 /// on the input
 /// <see cref="Antlr4.Runtime.ICharStream"/>
 /// to set the input
 /// position to the <em>end</em> of the current token. This behavior provides
 /// for efficient DFA representation of lexer actions which appear at the end
 /// of a lexer rule, even when the lexer rule matches a variable number of
 /// characters.</p>
 /// <p>Prior to traversing a match transition in the ATN, the current offset
 /// from the token start index is assigned to all position-dependent lexer
 /// actions which have not already been assigned a fixed offset. By storing
 /// the offsets relative to the token start index, the DFA representation of
 /// lexer actions which appear in the middle of tokens remains efficient due
 /// to sharing among tokens of the same length, regardless of their absolute
 /// position in the input stream.</p>
 /// <p>If the current executor already has offsets assigned to all
 /// position-dependent lexer actions, the method returns
 /// <code>this</code>
 /// .</p>
 /// </summary>
 /// <param name="offset">
 /// The current offset to assign to all position-dependent
 /// lexer actions which do not already have offsets assigned.
 /// </param>
 /// <returns>
 /// A
 /// <see cref="LexerActionExecutor"/>
 /// which stores input stream offsets
 /// for all position-dependent lexer actions.
 /// </returns>
 public virtual Antlr4.Runtime.Atn.LexerActionExecutor FixOffsetBeforeMatch(int offset)
 {
     ILexerAction[] updatedLexerActions = null;
     for (int i = 0; i < lexerActions.Length; i++)
     {
         if (lexerActions[i].IsPositionDependent && !(lexerActions[i] is LexerIndexedCustomAction))
         {
             if (updatedLexerActions == null)
             {
                 updatedLexerActions = (ILexerAction[])lexerActions.Clone();
             }
             updatedLexerActions[i] = new LexerIndexedCustomAction(offset, lexerActions[i]);
         }
     }
     if (updatedLexerActions == null)
     {
         return this;
     }
     return new Antlr4.Runtime.Atn.LexerActionExecutor(updatedLexerActions);
 }