@@ -17,49 +17,42 @@ const EXAMPLE_MAPPING = {
1717 automata : 'automata.sg' ,
1818 stackmachine : 'npda.sg' ,
1919 turing : 'turing.sg' ,
20- stack : 'stack.sg'
20+ stack : 'stack.sg' ,
21+ mll : 'proofnets/mll.sg' ,
22+ fomll : 'proofnets/fomll.sg'
2123} ;
2224
2325// Path configuration
2426const EXAMPLES_DIR = path . join ( __dirname , '..' , 'examples' ) ;
2527const OUTPUT_FILE = path . join ( __dirname , 'examples.js' ) ;
28+ const PRELUDE_FILE = path . join ( EXAMPLES_DIR , 'milkyway' , 'prelude.sg' ) ;
29+
30+ /**
31+ * Load and prepare prelude content for inlining
32+ */
33+ function loadPrelude ( ) {
34+ try {
35+ const preludeContent = fs . readFileSync ( PRELUDE_FILE , 'utf-8' ) ;
36+ return `' Prelude macros (normally imported)\n${ preludeContent . trim ( ) } ` ;
37+ } catch ( error ) {
38+ console . error ( '❌ Error loading prelude:' , error . message ) ;
39+ process . exit ( 1 ) ;
40+ }
41+ }
2642
2743/**
2844 * Process example file content for the playground
2945 * - Replace (use-macros "milkyway/prelude.sg") with inline macro definitions
3046 * - Adjust any other syntax needed for standalone execution
3147 */
32- function processExampleContent ( content , filename ) {
48+ function processExampleContent ( content , _filename , preludeMacros ) {
3349 // For files that use prelude macros, inline them
50+ // Handle both direct and relative paths to prelude
3451 if ( content . includes ( '(use-macros "milkyway/prelude.sg")' ) ) {
35- const preludeMacros = `' Prelude macros (normally imported)
36- (macro (spec X Y) (:= X Y))
37- (macro (:: Tested Test)
38- (== @(exec @#Tested #Test) ok))` ;
39-
4052 content = content . replace ( '(use-macros "milkyway/prelude.sg")' , preludeMacros ) ;
4153 }
42-
43- // Specific fixes for known issues
44- if ( filename === 'prolog.sg' ) {
45- // Change 'exec' to 'interact' in the graph traversal example (line 48)
46- content = content . replace (
47- '<show exec (process' ,
48- '<show interact (process'
49- ) ;
50- }
51-
52- if ( filename === 'stack.sg' ) {
53- // Change 'exec' to 'interact' in stack example
54- content = content . replace (
55- '<show exec (process' ,
56- '<show interact (process'
57- ) ;
58- }
59-
60- if ( filename === 'hello.sg' ) {
61- // Add a welcome comment
62- content = `' Hello World\n${ content } ` ;
54+ if ( content . includes ( '(use-macros "../milkyway/prelude.sg")' ) ) {
55+ content = content . replace ( '(use-macros "../milkyway/prelude.sg")' , preludeMacros ) ;
6356 }
6457
6558 return content . trim ( ) ;
@@ -71,6 +64,10 @@ function processExampleContent(content, filename) {
7164function buildExamples ( ) {
7265 console . log ( 'Building examples for Stellogen playground...\n' ) ;
7366
67+ // Load prelude once
68+ const preludeMacros = loadPrelude ( ) ;
69+ console . log ( '✓ Loaded prelude macros\n' ) ;
70+
7471 const examples = { } ;
7572 let successCount = 0 ;
7673 let errorCount = 0 ;
@@ -87,7 +84,7 @@ function buildExamples() {
8784 }
8885
8986 const content = fs . readFileSync ( filepath , 'utf-8' ) ;
90- const processed = processExampleContent ( content , filename ) ;
87+ const processed = processExampleContent ( content , filename , preludeMacros ) ;
9188 examples [ key ] = processed ;
9289
9390 console . log ( `✓ Processed: ${ filename } -> ${ key } ` ) ;
0 commit comments