1 /* 2 * Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 * Use of this file is governed by the BSD 3-clause license that 4 * can be found in the LICENSE.txt file in the project root. 5 */ 6 7 package org.antlr.v4.runtime.atn; 8 9 import org.antlr.v4.runtime.CharStream; 10 import org.antlr.v4.runtime.Lexer; 11 12 /** 13 * Represents a single action which can be executed following the successful 14 * match of a lexer rule. Lexer actions are used for both embedded action syntax 15 * and ANTLR 4's new lexer command syntax. 16 * 17 * @author Sam Harwell 18 * @since 4.2 19 */ 20 public interface LexerAction { 21 /** 22 * Gets the serialization type of the lexer action. 23 * 24 * @return The serialization type of the lexer action. 25 */ getActionType()26 LexerActionType getActionType(); 27 28 /** 29 * Gets whether the lexer action is position-dependent. Position-dependent 30 * actions may have different semantics depending on the {@link CharStream} 31 * index at the time the action is executed. 32 * 33 * <p>Many lexer commands, including {@code type}, {@code skip}, and 34 * {@code more}, do not check the input index during their execution. 35 * Actions like this are position-independent, and may be stored more 36 * efficiently as part of the {@link LexerATNConfig#lexerActionExecutor}.</p> 37 * 38 * @return {@code true} if the lexer action semantics can be affected by the 39 * position of the input {@link CharStream} at the time it is executed; 40 * otherwise, {@code false}. 41 */ isPositionDependent()42 boolean isPositionDependent(); 43 44 /** 45 * Execute the lexer action in the context of the specified {@link Lexer}. 46 * 47 * <p>For position-dependent actions, the input stream must already be 48 * positioned correctly prior to calling this method.</p> 49 * 50 * @param lexer The lexer instance. 51 */ execute(Lexer lexer)52 void execute(Lexer lexer); 53 } 54