1 /* 2 * Copyright (c) 2012-2018 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 module antlr.v4.runtime.atn.LexerAction; 8 9 import antlr.v4.runtime.InterfaceLexer; 10 import antlr.v4.runtime.atn.LexerActionType; 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 interface LexerAction 18 { 19 20 /** 21 * Gets the serialization type of the lexer action. 22 * 23 * @return The serialization type of the lexer action. 24 */ 25 public LexerActionType getActionType(); 26 27 /** 28 * Gets whether the lexer action is position-dependent. Position-dependent 29 * actions may have different semantics depending on the {@link CharStream} 30 * index at the time the action is executed. 31 * 32 * <p>Many lexer commands, including {@code type}, {@code skip}, and 33 * {@code more}, do not check the input index during their execution. 34 * Actions like this are position-independent, and may be stored more 35 * efficiently as part of the {@link LexerATNConfig#lexerActionExecutor}.</p> 36 * 37 * @return {@code true} if the lexer action semantics can be affected by the 38 * position of the input {@link CharStream} at the time it is executed; 39 * otherwise, {@code false}. 40 */ 41 public bool isPositionDependent(); 42 43 /** 44 * Execute the lexer action in the context of the specified {@link Lexer}. 45 * 46 * <p>For position-dependent actions, the input stream must already be 47 * positioned correctly prior to calling this method.</p> 48 * 49 * @param lexer The lexer instance. 50 */ 51 public void execute(InterfaceLexer lexer); 52 53 /** 54 * @uml 55 * @nothrow 56 */ 57 public size_t toHash() nothrow; 58 59 }