-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathToken.js
More file actions
66 lines (53 loc) · 1.68 KB
/
Token.js
File metadata and controls
66 lines (53 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* Copyright (c) 2012-2022 The ANTLR Project. All rights reserved.
* Use of this file is governed by the BSD 3-clause license that
* can be found in the LICENSE.txt file in the project root.
*/
/**
* A token has properties: text, type, line, character position in the line
* (so we can ignore tabs), token channel, index, and source from which
* we obtained this token.
*/
export default class Token {
constructor() {
this.source = null;
this.type = null; // token type of the token
this.channel = null; // The parser ignores everything not on DEFAULT_CHANNEL
this.start = null; // optional; return -1 if FIXME.
this.stop = null; // optional; return -1 if FIXME.
this.tokenIndex = null; // from 0..n-1 of the token object in the input stream
this.line = null; // line=1..n of the 1st character
this.column = null; // beginning of the line at which it occurs, 0..n-1
this._text = null; // text of the token.
}
getTokenSource() {
return this.source[0];
}
getInputStream() {
return this.source[1];
}
get text(){
return this._text;
}
set text(text) {
this._text = text;
}
}
Token.INVALID_TYPE = 0;
/**
* During lookahead operations, this "token" signifies we hit rule end ATN state
* and did not follow it despite needing to.
*/
Token.EPSILON = -2;
Token.MIN_USER_TOKEN_TYPE = 1;
Token.EOF = -1;
/**
* All tokens go to the parser (unless skip() is called in that rule)
* on a particular "channel". The parser tunes to a particular channel
* so that whitespace etc... can go to the parser on a "hidden" channel.
*/
Token.DEFAULT_CHANNEL = 0;
/**
* Anything on different channel than DEFAULT_CHANNEL is not parsed
* by parser.
*/
Token.HIDDEN_CHANNEL = 1;