1<?php
2
3declare(strict_types=1);
4
5namespace Antlr\Antlr4\Runtime\Atn\Actions;
6
7use Antlr\Antlr4\Runtime\Comparison\Hashable;
8use Antlr\Antlr4\Runtime\Lexer;
9
10/**
11 * Represents a single action which can be executed following the successful
12 * match of a lexer rule. Lexer actions are used for both embedded action syntax
13 * and ANTLR 4's new lexer command syntax.
14 *
15 * @author Sam Harwell
16 */
17interface LexerAction extends Hashable
18{
19    /**
20     * Gets the serialization type of the lexer action.
21     *
22     * @return int The serialization type of the lexer action.
23     */
24    public function getActionType() : int;
25
26    /**
27     * Gets whether the lexer action is position-dependent. Position-dependent
28     * actions may have different semantics depending on the {@see CharStream}
29     * index at the time the action is executed.
30     *
31     * Many lexer commands, including `type`, `skip`, and `more`, do not check
32     * the input index during their execution. Actions like this are
33     * position-independent, and may be stored more efficiently as part of the
34     * {@see LexerATNConfig::lexerActionExecutor()}.
35     *
36     * @return bool `true` if the lexer action semantics can be affected by the
37     *              position of the input {@see CharStream} at the time it is
38     *              executed; otherwise, `false`.
39     */
40    public function isPositionDependent() : bool;
41
42    /**
43     * Execute the lexer action in the context of the specified {@see Lexer}.
44     *
45     * For position-dependent actions, the input stream must already be
46     * positioned correctly prior to calling this method.
47     *
48     * @param Lexer $lexer The lexer instance.
49     */
50    public function execute(Lexer $lexer) : void;
51}
52