-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathweb.js
More file actions
30 lines (26 loc) · 781 Bytes
/
web.js
File metadata and controls
30 lines (26 loc) · 781 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
import { lexer } from './lexer.js';
import { parser } from './parse.js';
import { evaluate } from './eval.js';
export function runLizb(code) {
const tokens = lexer(code);
const ast = parser(tokens);
return evaluate(ast);
}
export async function runLizbScripts() {
const scripts = Array.from(document.querySelectorAll('script[type="text/lizb"]'));
for (const s of scripts) {
const code = s.src
? await (await fetch(s.src)).text() // same-origin or CORS-enabled
: (s.textContent ?? '');
try {
runLizb(code);
} catch (err) {
console.error('Lizb script error:', err);
}
}
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', runLizbScripts, { once: true });
} else {
runLizbScripts();
}