42 lines
914 B
JavaScript
42 lines
914 B
JavaScript
#!/usr/bin/env node
|
|
|
|
/**
|
|
* Basic syntax fixer for Strudel code.
|
|
* - Replaces ~ with -
|
|
* - Ensures setcps exists (adds default if missing)
|
|
* - Basic track control check
|
|
*/
|
|
|
|
const fs = require('fs');
|
|
|
|
function fixStrudelCode(code) {
|
|
let fixed = code;
|
|
|
|
// 1. Replace ~ with -
|
|
fixed = fixed.replace(/~/g, '-');
|
|
|
|
// 2. Ensure setcps exists at the beginning
|
|
if (!fixed.includes('setcps')) {
|
|
fixed = `setcps(120/60/4)
|
|
|
|
${fixed}`;
|
|
}
|
|
|
|
// 3. Simple warning/fix for track control (just a heuristic)
|
|
if (!fixed.includes('$:') && fixed.includes('s(')) {
|
|
// If it's a single line starting with s(, add $:
|
|
fixed = fixed.replace(/^s\(/gm, '$: s(');
|
|
}
|
|
|
|
return fixed;
|
|
}
|
|
|
|
// Read from stdin or file
|
|
const input = process.argv[2] ? fs.readFileSync(process.argv[2], 'utf8') : '';
|
|
if (input) {
|
|
process.stdout.write(fixStrudelCode(input));
|
|
} else {
|
|
// If no input, just exit
|
|
process.exit(0);
|
|
}
|