1 /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
2 * Use of this file is governed by the BSD 3-clause license that
3 * can be found in the LICENSE.txt file in the project root.
8 #include "BufferedTokenStream.h"
13 * This class extends {@link BufferedTokenStream} with functionality to filter
14 * token streams to tokens on a particular channel (tokens where
15 * {@link Token#getChannel} returns a particular value).
18 * This token stream provides access to all tokens by index or when calling
19 * methods like {@link #getText}. The channel filtering is only used for code
20 * accessing tokens via the lookahead methods {@link #LA}, {@link #LT}, and
24 * By default, tokens are placed on the default channel
25 * ({@link Token#DEFAULT_CHANNEL}), but may be reassigned by using the
26 * {@code ->channel(HIDDEN)} lexer command, or by using an embedded action to
27 * call {@link Lexer#setChannel}.
31 * Note: lexer rules which use the {@code ->skip} lexer command or call
32 * {@link Lexer#skip} do not produce tokens at all, so input text matched by
33 * such a rule will not be available as part of the token stream, regardless of
36 class ANTLR4CPP_PUBLIC CommonTokenStream : public BufferedTokenStream {
39 * Constructs a new {@link CommonTokenStream} using the specified token
40 * source and the default token channel ({@link Token#DEFAULT_CHANNEL}).
42 * @param tokenSource The token source.
44 CommonTokenStream(TokenSource *tokenSource);
47 * Constructs a new {@link CommonTokenStream} using the specified token
48 * source and filtering tokens to the specified channel. Only tokens whose
49 * {@link Token#getChannel} matches {@code channel} or have the
50 * {@link Token#getType} equal to {@link Token#EOF} will be returned by the
51 * token stream lookahead methods.
53 * @param tokenSource The token source.
54 * @param channel The channel to use for filtering tokens.
56 CommonTokenStream(TokenSource *tokenSource, size_t channel);
58 virtual Token* LT(ssize_t k) override;
60 /// Count EOF just once.
61 virtual int getNumberOfOnChannelTokens();
65 * Specifies the channel to use for filtering tokens.
68 * The default value is {@link Token#DEFAULT_CHANNEL}, which matches the
69 * default channel assigned to tokens created by the lexer.</p>
73 virtual ssize_t adjustSeekIndex(size_t i) override;
75 virtual Token* LB(size_t k) override;