UNPKG

4.28 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 { ATNSimulator } from "./atn/ATNSimulator";
6import { CharStream } from "./CharStream";
7import { Recognizer } from "./Recognizer";
8import { Token } from "./Token";
9import { TokenSource } from "./TokenSource";
10import { WritableToken } from "./WritableToken";
11export declare class CommonToken implements WritableToken {
12 /**
13 * An empty {@link Tuple2} which is used as the default value of
14 * {@link #source} for tokens that do not have a source.
15 */
16 protected static readonly EMPTY_SOURCE: {
17 source?: TokenSource;
18 stream?: CharStream;
19 };
20 /**
21 * This is the backing field for `type`.
22 */
23 private _type;
24 /**
25 * This is the backing field for {@link #getLine} and {@link #setLine}.
26 */
27 private _line;
28 /**
29 * This is the backing field for {@link #getCharPositionInLine} and
30 * {@link #setCharPositionInLine}.
31 */
32 private _charPositionInLine;
33 /**
34 * This is the backing field for {@link #getChannel} and
35 * {@link #setChannel}.
36 */
37 private _channel;
38 /**
39 * This is the backing field for {@link #getTokenSource} and
40 * {@link #getInputStream}.
41 *
42 * These properties share a field to reduce the memory footprint of
43 * {@link CommonToken}. Tokens created by a {@link CommonTokenFactory} from
44 * the same source and input stream share a reference to the same
45 * {@link Tuple2} containing these values.
46 */
47 protected source: {
48 source?: TokenSource;
49 stream?: CharStream;
50 };
51 /**
52 * This is the backing field for {@link #getText} when the token text is
53 * explicitly set in the constructor or via {@link #setText}.
54 *
55 * @see `text`
56 */
57 private _text?;
58 /**
59 * This is the backing field for `tokenIndex`.
60 */
61 protected index: number;
62 /**
63 * This is the backing field for `startIndex`.
64 */
65 protected start: number;
66 /**
67 * This is the backing field for `stopIndex`.
68 */
69 private stop;
70 constructor(type: number, text?: string, source?: {
71 source?: TokenSource;
72 stream?: CharStream;
73 }, channel?: number, start?: number, stop?: number);
74 /**
75 * Constructs a new {@link CommonToken} as a copy of another {@link Token}.
76 *
77 * If `oldToken` is also a {@link CommonToken} instance, the newly
78 * constructed token will share a reference to the {@link #text} field and
79 * the {@link Tuple2} stored in {@link #source}. Otherwise, {@link #text} will
80 * be assigned the result of calling {@link #getText}, and {@link #source}
81 * will be constructed from the result of {@link Token#getTokenSource} and
82 * {@link Token#getInputStream}.
83 *
84 * @param oldToken The token to copy.
85 */
86 static fromToken(oldToken: Token): CommonToken;
87 get type(): number;
88 set type(type: number);
89 get line(): number;
90 set line(line: number);
91 get text(): string | undefined;
92 /**
93 * Explicitly set the text for this token. If {code text} is not
94 * `undefined`, then {@link #getText} will return this value rather than
95 * extracting the text from the input.
96 *
97 * @param text The explicit text of the token, or `undefined` if the text
98 * should be obtained from the input along with the start and stop indexes
99 * of the token.
100 */
101 set text(text: string | undefined);
102 get charPositionInLine(): number;
103 set charPositionInLine(charPositionInLine: number);
104 get channel(): number;
105 set channel(channel: number);
106 get startIndex(): number;
107 set startIndex(start: number);
108 get stopIndex(): number;
109 set stopIndex(stop: number);
110 get tokenIndex(): number;
111 set tokenIndex(index: number);
112 get tokenSource(): TokenSource | undefined;
113 get inputStream(): CharStream | undefined;
114 toString(): string;
115 toString<TSymbol, ATNInterpreter extends ATNSimulator>(recognizer: Recognizer<TSymbol, ATNInterpreter> | undefined): string;
116}