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
|
// simple-debug.js - Debug the test result structure
import { createLexer } from './src/core/lexer.js';
import { createParser } from './src/core/parser.js';
import { createInterpreter } from './src/core/interpreter.js';
function runBabaCode(code) {
const lexer = createLexer(code);
const tokens = lexer.allTokens();
const parser = createParser(tokens);
const ast = parser.parse();
const host = {
jsBridgeConfig: {
allowedFunctions: new Set([
'JSON.parse', 'JSON.stringify',
'Math.abs', 'Math.floor', 'Math.ceil', 'Math.round',
'Math.min', 'Math.max', 'Math.random',
'console.log', 'console.warn', 'console.error',
'Date.now', 'performance.now'
])
},
io: {
out: () => {},
debug: () => {}
}
};
const interpreter = createInterpreter(ast, host);
interpreter.interpret();
return interpreter.scope.get('result');
}
const code = `result : io.callJS "Math.abs" [-42];`;
const result = runBabaCode(code);
console.log('Result:', result);
console.log('Type:', result?.type);
console.log('Properties:', result?.properties);
console.log('Has Ok?', result?.properties?.has('Ok'));
console.log('Ok value:', result?.properties?.get('Ok'));
|