diff options
| author | elioat <elioat@tilde.institute> | 2025-08-27 22:11:35 -0400 |
|---|---|---|
| committer | elioat <elioat@tilde.institute> | 2025-08-27 22:11:35 -0400 |
| commit | d696f2d52830caa196154a94b7ead4aee568ad26 (patch) | |
| tree | edc2031e405de6555741b5a7aa0a4cfb9f96405c | |
| parent | cc273f29b7d79a6083f5ebf8dd10ba8296f588bd (diff) | |
| download | tour-d696f2d52830caa196154a94b7ead4aee568ad26.tar.gz | |
*
| -rw-r--r-- | js/baba-yaga/build-playground.js | 54 | ||||
| -rw-r--r-- | js/baba-yaga/playground/example.baba | 94 | ||||
| -rw-r--r-- | js/baba-yaga/playground/index.html | 12 | ||||
| -rw-r--r-- | js/baba-yaga/playground/playground.js | 6 |
4 files changed, 109 insertions, 57 deletions
diff --git a/js/baba-yaga/build-playground.js b/js/baba-yaga/build-playground.js index 8878137..c66c31c 100644 --- a/js/baba-yaga/build-playground.js +++ b/js/baba-yaga/build-playground.js @@ -39,17 +39,27 @@ function copyFile(src, dest) { } /** - * Copy directory recursively, excluding node_modules + * Copy directory recursively, excluding specified items */ function copyDir(src, dest) { ensureDir(dest); const entries = fs.readdirSync(src, { withFileTypes: true }); + // Items to skip during copy + const skipItems = [ + 'node_modules', + 'DEV.md', + 'README.md', + 'package.json', + 'playground.test.js', + 'bun.lockb' + ]; + for (const entry of entries) { - // Skip node_modules directory - if (entry.name === 'node_modules') { - console.log(`āļø Skipping: ${entry.name} (not needed for deployment)`); + // Skip specified items + if (skipItems.includes(entry.name)) { + console.log(`Skipping: ${entry.name} (not needed for deployment)`); continue; } @@ -68,7 +78,7 @@ function copyDir(src, dest) { * Main build function */ function build() { - console.log('š Building Baba Yaga Playground...\n'); + console.log('Building Baba Yaga Playground...\n'); try { // Clean and create dist directory @@ -78,49 +88,49 @@ function build() { ensureDir(DIST_DIR); // Copy playground files (excluding node_modules) - console.log('š Copying playground files...'); + console.log('Copying playground files...'); copyDir(SOURCE_DIR, DIST_DIR); // Ensure Go Mono font is copied (it's needed for the playground styling) - console.log('š Ensuring Go Mono font is available...'); + console.log('Ensuring Go Mono font is available...'); const fontSrc = path.join(SOURCE_DIR, 'Go-Mono.ttf'); const fontDest = path.join(DIST_DIR, 'Go-Mono.ttf'); if (fs.existsSync(fontSrc)) { fs.copyFileSync(fontSrc, fontDest); - console.log('ā Copied Go-Mono.ttf'); + console.log('Copied Go-Mono.ttf'); } else { - console.warn('ā ļø Go-Mono.ttf not found in playground source'); + console.warn('Go-Mono.ttf not found in playground source'); } // Ensure browser-wrapper.js is copied (it's needed by playground.js) - console.log('š Ensuring browser-wrapper.js is available...'); + console.log('Ensuring browser-wrapper.js is available...'); const browserWrapperSrc = path.join(SOURCE_DIR, 'browser-wrapper.js'); const browserWrapperDest = path.join(DIST_DIR, 'browser-wrapper.js'); if (fs.existsSync(browserWrapperSrc)) { fs.copyFileSync(browserWrapperSrc, browserWrapperDest); - console.log('ā Copied browser-wrapper.js'); + console.log('Copied browser-wrapper.js'); } else { - console.warn('ā ļø browser-wrapper.js not found in source'); + console.warn('browser-wrapper.js not found in source'); } // Copy core modules - console.log('\nš Copying core modules...'); + console.log('\nCopying core modules...'); const coreDest = path.join(DIST_DIR, 'core'); copyDir(CORE_DIR, coreDest); // Copy legacy modules (needed for fallback lexer) - console.log('\nš Copying legacy modules...'); + console.log('\nCopying legacy modules...'); const legacyDir = path.join(__dirname, 'src', 'legacy'); const legacyDest = path.join(DIST_DIR, 'legacy'); if (fs.existsSync(legacyDir)) { copyDir(legacyDir, legacyDest); - console.log('ā Copied legacy modules'); + console.log('Copied legacy modules'); } else { - console.warn('ā ļø Legacy directory not found'); + console.warn('Legacy directory not found'); } // Copy additional files - console.log('\nš Copying additional files...'); + console.log('\nCopying additional files...'); const additionalFiles = [ { src: 'LICENSE', dest: 'LICENSE.txt' }, { src: 'docs/ref.txt', dest: 'ref.txt' } @@ -131,14 +141,14 @@ function build() { const destPath = path.join(DIST_DIR, dest); if (fs.existsSync(srcPath)) { fs.copyFileSync(srcPath, destPath); - console.log(`ā Copied: ${src} ā ${dest}`); + console.log(`Copied: ${src} ā ${dest}`); } else { - console.warn(`ā ļø Warning: ${src} not found`); + console.warn(`Warning: ${src} not found`); } }); // Update import paths in playground.js - console.log('\nš§ Updating import paths...'); + console.log('\nUpdating import paths...'); const playgroundJsPath = path.join(DIST_DIR, 'playground.js'); let playgroundJs = fs.readFileSync(playgroundJsPath, 'utf8'); @@ -149,7 +159,7 @@ function build() { ); fs.writeFileSync(playgroundJsPath, playgroundJs); - console.log('ā Updated import paths in playground.js'); + console.log('Updated import paths in playground.js'); // Create a simple README const readmeContent = `# Baba Yaga Playground @@ -192,7 +202,7 @@ This directory contains everything needed to run the playground. You can: console.log('2. Or deploy the entire directory to any static hosting service'); } catch (error) { - console.error('\nā Build failed:', error.message); + console.error('\nBuild failed:', error.message); process.exit(1); } } diff --git a/js/baba-yaga/playground/example.baba b/js/baba-yaga/playground/example.baba index b6dfc89..79d5bf0 100644 --- a/js/baba-yaga/playground/example.baba +++ b/js/baba-yaga/playground/example.baba @@ -1,22 +1,48 @@ -// Example Baba Yaga Program // Demonstrates core language features +io.out "=== Basic Variables and Operations ==="; // Variables and basic operations x : 42; y : x + 8; message : "Hello, Baba Yaga!"; +io.out "x ="; +io.out x; +io.out "y ="; +io.out y; +io.out "message ="; +io.out message; + +io.out "\n=== Functions and Currying ==="; // Functions and currying add : a b -> a + b; multiply : a b -> a * b; addTen : add 10; +io.out "addTen 5 ="; +io.out (addTen 5); +io.out "multiply 6 7 ="; +io.out (multiply 6 7); + +io.out "\n=== Higher-Order Functions with Lists ==="; // Higher-order functions with lists numbers : [1, 2, 3, 4, 5]; +io.out "Original numbers:"; +io.out numbers; + doubled : map (x -> x * 2) numbers; +io.out "Doubled:"; +io.out doubled; + evens : filter (x -> x % 2 = 0) doubled; +io.out "Even numbers from doubled:"; +io.out evens; + sum : reduce (acc x -> acc + x) 0 evens; +io.out "Sum of evens:"; +io.out sum; +io.out "\n=== Pattern Matching ==="; // Pattern matching classify : n -> when n is @@ -25,40 +51,60 @@ classify : n -> Int then when (n > 10) is true then "big" _ then "small" _ then "unknown"; +io.out "classify 0 ="; +io.out (classify 0); +io.out "classify 15 ="; +io.out (classify 15); +io.out "classify 3 ="; +io.out (classify 3); + +io.out "\n=== Error Handling with Result Types ==="; // Error handling with Result types safeDivide : a b -> when b is 0 then Err "Division by zero" _ then Ok (a / b); +result1 : safeDivide 10 2; +result2 : safeDivide 10 0; +io.out "safeDivide 10 2 ="; +io.out result1; +io.out "safeDivide 10 0 ="; +io.out result2; + +io.out "\n=== Table (Object) Operations ==="; // Table (object) operations person : { name: "Lucy Snowe", age: 23, city: "Villette" }; +io.out "Person table:"; +io.out person; +io.out "\n=== JavaScript Interop - JSON Parsing ==="; +jsonStr : "{\"name\": \"Baba Yaga\", \"age\": 200}"; +parseResult : io.callJS "JSON.parse" [jsonStr]; +io.out "Parsed JSON:"; +io.out parseResult; -io.out "Basic values:"; -io.out x; -io.out y; -io.out message; +// Property access +propResult : when parseResult is + Ok obj then io.getProperty obj "name" + Err msg then Err msg; -io.out "Function results:"; -io.out (addTen 5); -io.out (multiply 6 7); +io.out "Extracted name property:"; +io.out propResult; -io.out "List operations:"; -io.out doubled; -io.out evens; -io.out sum; - -io.out "Pattern matching:"; -io.out (classify 0); -io.out (classify 15); -io.out (classify 3); +io.out "\n=== JavaScript Interop - Array Operations ==="; +// Array operations +babaList : [1, 2, 3, 4, 5]; +io.out "Baba Yaga list:"; +io.out babaList; -io.out "Error handling:"; -result1 : safeDivide 10 2; -result2 : safeDivide 10 0; -io.out result1; -io.out result2; +jsArray : io.listToJSArray babaList; +jsonResult : io.callJS "JSON.stringify" [jsArray]; +io.out "Converted to JSON:"; +io.out jsonResult; -io.out "Table operations:"; -io.out person;
\ No newline at end of file +io.out "\n=== JavaScript Interop - Error Handling ==="; +// Error handling +errorResult : io.callJS "invalidFunction" []; +io.out "Invalid function call result:"; +io.out errorResult;
\ No newline at end of file diff --git a/js/baba-yaga/playground/index.html b/js/baba-yaga/playground/index.html index 75f89e6..64e3fc0 100644 --- a/js/baba-yaga/playground/index.html +++ b/js/baba-yaga/playground/index.html @@ -15,9 +15,9 @@ } :root { - --font-size: 22px; - --font-size-small: 18px; - --spacing: 8px; + --font-size: 18px; + --font-size-small: 16px; + --spacing: 4px; --border: #000000; --bg: #ffffff; --bg-secondary: #f8f8f8; @@ -43,7 +43,7 @@ } .container { - max-width: 1200px; + max-width: 75rem; margin: 0 auto; display: flex; flex-direction: column; @@ -83,12 +83,10 @@ .code-input:focus { border: 2px solid var(--border-color); - box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1); } .btn:focus { outline: 2px solid var(--border-color); - outline-offset: 2px; } .input-label, @@ -308,8 +306,6 @@ .code-input, .console { - height: 40vh; - min-height: 150px; font-size: var(--font-size-small); padding: 6px; } diff --git a/js/baba-yaga/playground/playground.js b/js/baba-yaga/playground/playground.js index b2cb91c..3089077 100644 --- a/js/baba-yaga/playground/playground.js +++ b/js/baba-yaga/playground/playground.js @@ -48,7 +48,7 @@ export class BabaYagaPlayground { // Show a simple working example this.log('Try this example (click to add it to the editor):', 'info'); - this.log('x : 42;\nio.out x;\ny : x + 8;\nio.out y;', 'example'); + this.log('\nx : 42;\nio.out x;\ny : x + 8;\nio.out y;', 'example'); // Add a button to load the working example this.log('Or load the working example file:', 'info'); @@ -587,7 +587,7 @@ export class BabaYagaPlayground { * Load a simple, working example program by default */ loadDefaultExample() { - const defaultCode = `// Simple Baba Yaga Examples + const defaultCode = ` // Basic arithmetic x : 42; y : x + 8; @@ -609,7 +609,7 @@ io.out result;`; this.codeInput.value = defaultCode; this.updateCursorInfo(); - this.log('Default example loaded - ready to run!', 'success'); + this.log('Default example loaded.', 'success'); } /** |