1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | var inspect = require('sys').inspect;
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | var Token = exports = module.exports = function Token(type, val) {
|
23 | this.type = type;
|
24 | this.val = val;
|
25 | };
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | Token.prototype.inspect = function(){
|
35 | var val = ' ' + inspect(this.val);
|
36 | return '[Token:' + this.lineno + ' '
|
37 | + '\x1b[32m' + this.type + '\x1b[0m'
|
38 | + '\x1b[33m' + (this.val ? val : '') + '\x1b[0m'
|
39 | + ']';
|
40 | };
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | Token.prototype.toString = function(){
|
50 | return (undefined === this.val
|
51 | ? this.type
|
52 | : this.val).toString();
|
53 | };
|