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 "TokenFactory.h"
13 * This default implementation of {@link TokenFactory} creates
14 * {@link CommonToken} objects.
16 class ANTLR4CPP_PUBLIC CommonTokenFactory : public TokenFactory<CommonToken> {
19 * The default {@link CommonTokenFactory} instance.
22 * This token factory does not explicitly copy token text when constructing
25 static const std::unique_ptr<TokenFactory<CommonToken>> DEFAULT;
29 * Indicates whether {@link CommonToken#setText} should be called after
30 * constructing tokens to explicitly set the text. This is useful for cases
31 * where the input stream might not be able to provide arbitrary substrings
32 * of text from the input after the lexer creates a token (e.g. the
33 * implementation of {@link CharStream#getText} in
34 * {@link UnbufferedCharStream} throws an
35 * {@link UnsupportedOperationException}). Explicitly setting the token text
36 * allows {@link Token#getText} to be called at any time regardless of the
37 * input stream implementation.
40 * The default value is {@code false} to avoid the performance and memory
41 * overhead of copying text for every token unless explicitly requested.</p>
47 * Constructs a {@link CommonTokenFactory} with the specified value for
51 * When {@code copyText} is {@code false}, the {@link #DEFAULT} instance
52 * should be used instead of constructing a new instance.</p>
54 * @param copyText The value for {@link #copyText}.
56 CommonTokenFactory(bool copyText);
59 * Constructs a {@link CommonTokenFactory} with {@link #copyText} set to
63 * The {@link #DEFAULT} instance should be used instead of calling this
68 virtual std::unique_ptr<CommonToken> create(std::pair<TokenSource*, CharStream*> source, size_t type,
69 const std::string &text, size_t channel, size_t start, size_t stop, size_t line, size_t charPositionInLine) override;
71 virtual std::unique_ptr<CommonToken> create(size_t type, const std::string &text) override;