This repository has been archived by the owner on Nov 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdeps.js
98 lines (90 loc) · 2.81 KB
/
deps.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
95
96
97
98
export {
assert,
assertEquals,
} from "https://deno.land/[email protected]/testing/asserts.ts";
export {
dirname,
extname,
join,
} from "https://deno.land/[email protected]/path/mod.ts";
export { default as isExpression } from "https://esm.sh/[email protected]";
export * as characterParser from "https://esm.sh/[email protected]";
export { default as constantinople } from "https://esm.sh/[email protected]";
export { default as addWith } from "https://esm.sh/[email protected]";
export function stringify(obj) {
if (obj instanceof Date) {
return "new Date(" + stringify(obj.toISOString()) + ")";
}
if (obj === undefined) {
return "undefined";
}
return JSON.stringify(obj)
.replace(/\u2028/g, "\\u2028")
.replace(/\u2029/g, "\\u2029")
.replace(/</g, "\\u003C")
.replace(/>/g, "\\u003E")
.replace(/\//g, "\\u002F");
}
export const selfClosing = {
"area": true,
"base": true,
"br": true,
"col": true,
"embed": true,
"hr": true,
"img": true,
"input": true,
"link": true,
"meta": true,
"param": true,
"source": true,
"track": true,
"wbr": true,
};
export const doctypes = {
"html": "<!DOCTYPE html>",
"xml": '<?xml version="1.0" encoding="utf-8" ?>',
"transitional":
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
"strict":
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
"frameset":
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
"1.1":
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
"basic":
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">',
"mobile":
'<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">',
"plist":
'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">',
};
export class TokenStream {
constructor(tokens) {
if (!Array.isArray(tokens)) {
throw new TypeError("tokens must be passed to TokenStream as an array.");
}
this._tokens = tokens;
}
lookahead(index) {
if (this._tokens.length <= index) {
throw new Error("Cannot read past the end of a stream");
}
return this._tokens[index];
}
peek() {
if (this._tokens.length === 0) {
throw new Error("Cannot read past the end of a stream");
}
return this._tokens[0];
}
advance() {
if (this._tokens.length === 0) {
throw new Error("Cannot read past the end of a stream");
}
return this._tokens.shift();
}
defer(token) {
this._tokens.unshift(token);
}
}