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 | */
|
5 | import { CharStream } from "./CharStream";
|
6 | import { Token } from "./Token";
|
7 | import { TokenFactory } from "./TokenFactory";
|
8 | import { TokenSource } from "./TokenSource";
|
9 | /**
|
10 | * Provides an implementation of {@link TokenSource} as a wrapper around a list
|
11 | * of {@link Token} objects.
|
12 | *
|
13 | * If the final token in the list is an {@link Token#EOF} token, it will be used
|
14 | * as the EOF token for every call to {@link #nextToken} after the end of the
|
15 | * list is reached. Otherwise, an EOF token will be created.
|
16 | */
|
17 | export declare class ListTokenSource implements TokenSource {
|
18 | /**
|
19 | * The wrapped collection of {@link Token} objects to return.
|
20 | */
|
21 | protected tokens: Token[];
|
22 | /**
|
23 | * The name of the input source. If this value is `undefined`, a call to
|
24 | * {@link #getSourceName} should return the source name used to create the
|
25 | * the next token in {@link #tokens} (or the previous token if the end of
|
26 | * the input has been reached).
|
27 | */
|
28 | private _sourceName?;
|
29 | /**
|
30 | * The index into {@link #tokens} of token to return by the next call to
|
31 | * {@link #nextToken}. The end of the input is indicated by this value
|
32 | * being greater than or equal to the number of items in {@link #tokens}.
|
33 | */
|
34 | protected i: number;
|
35 | /**
|
36 | * This field caches the EOF token for the token source.
|
37 | */
|
38 | protected eofToken?: Token;
|
39 | /**
|
40 | * This is the backing field for {@link #getTokenFactory} and
|
41 | * {@link setTokenFactory}.
|
42 | */
|
43 | private _factory;
|
44 | /**
|
45 | * Constructs a new {@link ListTokenSource} instance from the specified
|
46 | * collection of {@link Token} objects and source name.
|
47 | *
|
48 | * @param tokens The collection of {@link Token} objects to provide as a
|
49 | * {@link TokenSource}.
|
50 | * @param sourceName The name of the {@link TokenSource}. If this value is
|
51 | * `undefined`, {@link #getSourceName} will attempt to infer the name from
|
52 | * the next {@link Token} (or the previous token if the end of the input has
|
53 | * been reached).
|
54 | *
|
55 | * @exception NullPointerException if `tokens` is `undefined`
|
56 | */
|
57 | constructor(tokens: Token[], sourceName?: string);
|
58 | /**
|
59 | * { }
|
60 | */
|
61 | get charPositionInLine(): number;
|
62 | /**
|
63 | * {@inheritDoc}
|
64 | */
|
65 | nextToken(): Token;
|
66 | /**
|
67 | * {@inheritDoc}
|
68 | */
|
69 | get line(): number;
|
70 | /**
|
71 | * {@inheritDoc}
|
72 | */
|
73 | get inputStream(): CharStream | undefined;
|
74 | /**
|
75 | * {@inheritDoc}
|
76 | */
|
77 | get sourceName(): string;
|
78 | /**
|
79 | * {@inheritDoc}
|
80 | */
|
81 | set tokenFactory(factory: TokenFactory);
|
82 | /**
|
83 | * {@inheritDoc}
|
84 | */
|
85 | get tokenFactory(): TokenFactory;
|
86 | }
|