diff options
Diffstat (limited to 'js/baba-yaga/debug-property.js')
-rw-r--r-- | js/baba-yaga/debug-property.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/js/baba-yaga/debug-property.js b/js/baba-yaga/debug-property.js new file mode 100644 index 0000000..97bb0cb --- /dev/null +++ b/js/baba-yaga/debug-property.js @@ -0,0 +1,47 @@ +// debug-property.js - Debug property access test + +import { createLexer } from './src/core/lexer.js'; +import { createParser } from './src/core/parser.js'; +import { createInterpreter } from './src/core/interpreter.js'; + +const code = ` + jsObj : io.callJS "JSON.parse" ["{\\"x\\": 42, \\"y\\": 24}"]; + result : when jsObj is + Ok obj then io.getProperty obj "x" + Err msg then Err msg; + result; +`; + +console.log('Code:', 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: (...args) => console.log('[OUT]', ...args), + debug: (...args) => console.log('[DEBUG]', ...args) + } +}; + +const interpreter = createInterpreter(ast, host); +interpreter.interpret(); + +console.log('All variables in scope:'); +for (const [key, value] of interpreter.scope.entries()) { + console.log(` ${key}:`, value); +} + +const result = interpreter.scope.get('result'); +console.log('Final result:', result); |