-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtoken.js
43 lines (33 loc) · 1.04 KB
/
token.js
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
// # Copyright (c) 2014-2021 Feudal Code Limitada - MIT license #
"use strict"
export function createToken(row, col, kind, value) {
const token = new Token(row, col, kind, value)
Object.seal(token)
return token
}
export function tokenToString(token) {
let sRow = token.row.toString()
while (sRow.length < 4) { sRow = " " + sRow }
let sCol = token.col.toString()
while (sCol.length < 4) { sCol += " " }
let sKind = token.kind
while (sKind.length < 18) { sKind = " " + sKind }
const sValue = token.value
return (sRow + ":" + sCol + sKind + " " + sValue)
}
// constructor ////////////////////////////////////////////////////////////////
function Token(row, col, kind, value) {
this.rat = null
this.row = row
this.col = col
this.kind = kind
this.value = value
// during declaration:
this.isImport = false
this.isConstant = false
// after declaration:
this.wasUsed = false
this.wasAssigned = false
this.wasExported = false
}
//