-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToken.java
56 lines (48 loc) · 1.39 KB
/
Token.java
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
/**
* A token is a contiguous sequence of characters in a text,
* such as an identifier, an operator, or a literal.
*/
public final class Token {
private final TokenType type;
private final String text;
private final int startPosition;
/**
* Create a new Token.
* @param type the kind of token
* @param text the contents (characters) making up the token
* @param startPosition the position in the text where the token starts
*/
public Token(final TokenType type, final String text, final int startPosition) {
this.type = type;
this.text = text;
this.startPosition = startPosition;
}
/**
* Get the type of this token.
* @return the kind of token this is
*/
public TokenType getType() {
return type;
}
/**
* Get the text making up this token.
* @return the contents of this token
*/
public String getText() {
return text;
}
/**
* Get the start position of this token in the text.
* @return the position of the first character of this token
*/
public int getStartPosition() {
return startPosition;
}
/**
* Get the end position of this token in the text.
* @return the position just after the last character of this token
*/
public int getEndPosition() {
return startPosition + text.length();
}
}