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
99
100
101
102
103
104
105
106
107
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Module Loading Debug</title>
</head>
<body>
<h1>Module Loading Debug</h1>
<div id="status">Loading...</div>
<div id="results"></div>
<!-- Baba Yaga Language Components -->
<script src="../../lexer.js" type="module"></script>
<script src="../../parser.js" type="module"></script>
<script src="../../interpreter.js" type="module"></script>
<script type="module">
const statusDiv = document.getElementById('status');
const resultsDiv = document.getElementById('results');
function log(message, type = 'info') {
const color = type === 'error' ? 'red' : type === 'success' ? 'green' : 'black';
resultsDiv.innerHTML += `<p style="color: ${color}">${message}</p>`;
}
async function debugModules() {
try {
statusDiv.textContent = 'Checking module loading...';
// Wait a bit for modules to load
await new Promise(resolve => setTimeout(resolve, 100));
log('=== Module Loading Debug ===');
// Check global scope
log('Global scope check:');
log(`- window.createLexer: ${typeof window.createLexer}`);
log(`- window.createParser: ${typeof window.createParser}`);
log(`- window.createInterpreter: ${typeof window.createInterpreter}`);
// Check if functions are available
log('Function availability check:');
log(`- createLexer: ${typeof createLexer}`);
log(`- createParser: ${typeof createParser}`);
log(`- createInterpreter: ${typeof createInterpreter}`);
if (typeof createLexer === 'undefined') {
log('❌ createLexer is not defined', 'error');
} else {
log('✅ createLexer is available', 'success');
}
if (typeof createParser === 'undefined') {
log('❌ createParser is not defined', 'error');
} else {
log('✅ createParser is available', 'success');
}
if (typeof createInterpreter === 'undefined') {
log('❌ createInterpreter is not defined', 'error');
} else {
log('✅ createInterpreter is available', 'success');
}
// Try to use them if available
if (typeof createLexer !== 'undefined' && typeof createParser !== 'undefined') {
log('Testing basic functionality...');
try {
const testCode = 'add : x y -> x + y;';
const lexer = createLexer(testCode);
const tokens = lexer.allTokens();
log(`✅ Lexer test passed: ${tokens.length} tokens`);
const parser = createParser(tokens);
const ast = parser.parse();
log(`✅ Parser test passed: AST type = ${ast.type}`);
statusDiv.textContent = 'All tests passed! 🎉';
statusDiv.style.color = 'green';
} catch (error) {
log(`❌ Functionality test failed: ${error.message}`, 'error');
statusDiv.textContent = 'Tests failed! ❌';
statusDiv.style.color = 'red';
}
} else {
log('❌ Cannot test functionality - modules not loaded', 'error');
statusDiv.textContent = 'Modules not loaded! ❌';
statusDiv.style.color = 'red';
}
} catch (error) {
log(`❌ Debug failed: ${error.message}`, 'error');
statusDiv.textContent = 'Debug failed! ❌';
statusDiv.style.color = 'red';
}
}
// Run debug when page loads
document.addEventListener('DOMContentLoaded', debugModules);
</script>
</body>
</html>
|