-
Notifications
You must be signed in to change notification settings - Fork 1
/
token.js
94 lines (76 loc) · 2.48 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
;(function (root, factory) {
if (typeof exports === 'object') {
// CommonJS
factory(require, exports, module);
} else if (typeof define === 'function' && define.amd) {
// AMD
define(['require', 'exports', 'module', 'cla55'], factory);
} else {
console && console.error('Unsupported module environment.'); // jshint ignore:line
}
}(this, function (require, exports, module) {
'use strict';
var Cla55 = require('cla55'),
Token;
Token = Cla55.extend({
constructor: function constructor(type, value, range, loc) {
this.type = type;
this.value = value;
this.range = range;
this.loc = loc;
},
hasValue: function hasValue() {
var match,
value,
i,
l;
for (i = 0, l = arguments.length; i < l; i++) {
value = arguments[i];
match = value instanceof RegExp ? value.test(this.value) : this.value === value;
if (match) {
return true;
}
}
return false;
},
hasNotValue: function hasNotValue() {
return !this.hasValue.apply(this, arguments);
},
is: function is() {
var notExpr = /^Not/,
not,
match,
name,
i,
l;
for (i = 0, l = arguments.length; i < l; i++) {
name = arguments[i];
not = notExpr.test(name) && (name = name.replace(notExpr, '')) && true;
match = (this['_is' + name] && this['_is' + name]()) || this.type === name;
if (not && !match || !not && match) {
return true;
}
}
return false;
},
isNot: function isNot() {
return !this.is.apply(this, arguments);
},
// Special tests
_isEmpty: function isEmpty() {
return this.is('LineBreak') || this.is('WhiteSpace');
},
_isNumberIdentifier: function isNumberIdentifier() {
return this.is('Number') && this.hasValue(/^[0-9]+$/);
},
toJSON: function toJSON() {
return {
type: this.type,
value: this.value,
range: this.range,
loc: this.loc
};
}
});
module.exports = Token;
}));