UNPKG

2.27 kBTypeScriptView Raw
1/*!
2 * Copyright 2016 The ANTLR Project. All rights reserved.
3 * Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
4 */
5import { CharStream } from "./CharStream";
6import { CommonToken } from "./CommonToken";
7import { TokenFactory } from "./TokenFactory";
8import { TokenSource } from "./TokenSource";
9/**
10 * This default implementation of {@link TokenFactory} creates
11 * {@link CommonToken} objects.
12 */
13export declare class CommonTokenFactory implements TokenFactory {
14 /**
15 * Indicates whether {@link CommonToken#setText} should be called after
16 * constructing tokens to explicitly set the text. This is useful for cases
17 * where the input stream might not be able to provide arbitrary substrings
18 * of text from the input after the lexer creates a token (e.g. the
19 * implementation of {@link CharStream#getText} in
20 * {@link UnbufferedCharStream}
21 * {@link UnsupportedOperationException}). Explicitly setting the token text
22 * allows {@link Token#getText} to be called at any time regardless of the
23 * input stream implementation.
24 *
25 * The default value is `false` to avoid the performance and memory
26 * overhead of copying text for every token unless explicitly requested.
27 */
28 protected copyText: boolean;
29 /**
30 * Constructs a {@link CommonTokenFactory} with the specified value for
31 * {@link #copyText}.
32 *
33 * When `copyText` is `false`, the {@link #DEFAULT} instance
34 * should be used instead of constructing a new instance.
35 *
36 * @param copyText The value for {@link #copyText}.
37 */
38 constructor(copyText?: boolean);
39 create(source: {
40 source?: TokenSource;
41 stream?: CharStream;
42 }, type: number, text: string | undefined, channel: number, start: number, stop: number, line: number, charPositionInLine: number): CommonToken;
43 createSimple(type: number, text: string): CommonToken;
44}
45export declare namespace CommonTokenFactory {
46 /**
47 * The default {@link CommonTokenFactory} instance.
48 *
49 * This token factory does not explicitly copy token text when constructing
50 * tokens.
51 */
52 const DEFAULT: TokenFactory;
53}