-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToken.ts
More file actions
37 lines (33 loc) · 684 Bytes
/
Token.ts
File metadata and controls
37 lines (33 loc) · 684 Bytes
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
import { Position } from './Position'
export class Token {
type: string
value: any | null
posStart: Position
posEnd: Position
constructor(
_type: string,
value: any | null = null,
posStart: Position | null = null,
posEnd: Position | null = null
) {
this.type = _type
this.value = value
if (posStart) {
this.posStart = posStart.copy()
this.posEnd = posStart.copy()
this.posEnd.advance()
}
if (posEnd) {
this.posEnd = posEnd.copy()
}
}
matches(_type: string, value: any | null) {
return this.type === _type && this.value === value
}
asString() {
if (this.value) {
return `${this.type}:${this.value}`
}
return `${this.type}`
}
}