about summary refs log tree commit diff stats
path: root/js/baba-yaga/debug-when.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/baba-yaga/debug-when.js')
-rw-r--r--js/baba-yaga/debug-when.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/js/baba-yaga/debug-when.js b/js/baba-yaga/debug-when.js
new file mode 100644
index 0000000..c23dc87
--- /dev/null
+++ b/js/baba-yaga/debug-when.js
@@ -0,0 +1,38 @@
+// debug-when.js - Debug when expression with Result types
+
+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}"];
+  debug.inspect jsObj;
+  
+  result : when jsObj is
+    Ok obj then obj
+    Err msg then "error";
+  
+  debug.inspect result;
+  result;
+`;
+
+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'])
+  },
+  io: {
+    out: (...args) => console.log('[OUT]', ...args),
+    debug: (...args) => console.log('[DEBUG]', ...args)
+  }
+};
+
+const interpreter = createInterpreter(ast, host);
+interpreter.interpret();
+
+const result = interpreter.scope.get('result');
+console.log('Final result:', result);