feat: add mondough package to run strudel via mondo

This commit is contained in:
Felix Roos
2025-03-16 10:49:18 +01:00
parent 11196fb1e6
commit fae59a6bcd
8 changed files with 221 additions and 5 deletions
+17 -5
View File
@@ -19,8 +19,11 @@ export class MondoParser {
pipe: /^\./,
stack: /^,/,
op: /^[*/]/,
plain: /^[a-zA-Z0-9-]+/,
plain: /^[a-zA-Z0-9-_]+/,
};
constructor(config) {
this.config = config;
}
// matches next token
next_token(code) {
for (let type in this.token_types) {
@@ -29,7 +32,7 @@ export class MondoParser {
return { type, value: match[0] };
}
}
throw new Error(`zilp: could not match '${code}'`);
throw new Error(`mondo: could not match '${code}'`);
}
// takes code string, returns list of matched tokens (if valid)
tokenize(code) {
@@ -182,7 +185,7 @@ export class MondoParser {
const [callee, ...rest] = right.children;
const leftSide = children.slice(0, pipeIndex - 1);
const left = children[pipeIndex - 1];
const args = [callee, left, ...rest];
let args = [callee, left, ...rest];
const call = { type: 'list', children: args };
children = [...leftSide, call, ...rightSide];
} else {
@@ -200,6 +203,10 @@ export class MondoParser {
}
return children;
}
flip_call(children) {
let [name, first, ...rest] = children;
return [name, ...rest, first];
}
parse_pair(open_type, close_type) {
this.consume(open_type);
const children = [];
@@ -252,9 +259,10 @@ export function printAst(ast, compact = false, lvl = 0) {
// lisp runner
export class MondoRunner {
constructor(lib) {
this.parser = new MondoParser();
constructor(lib, config = {}) {
this.parser = new MondoParser(config);
this.lib = lib;
this.config = config;
}
// a helper to check conditions and throw if they are not met
assert(condition, error) {
@@ -264,6 +272,7 @@ export class MondoRunner {
}
run(code) {
const ast = this.parser.parse(code);
console.log(printAst(ast));
return this.call(ast);
}
call(ast) {
@@ -298,6 +307,9 @@ export class MondoRunner {
// look up function in lib
const fn = this.lib[name];
this.assert(fn, `function call: unknown function name "${name}"`);
if (this.lib.call) {
return this.lib.call(fn, args, name);
}
return fn(...args);
}
}
+3
View File
@@ -0,0 +1,3 @@
# @strudel/mondough
connects mondo to strudel.
+35
View File
@@ -0,0 +1,35 @@
import { strudelScope, reify, fast, slow, isControlName } from '@strudel/core';
import { MondoRunner } from '../mondo/mondo.mjs';
let runner = new MondoRunner(strudelScope, { pipepost: true });
//strudelScope.plain = reify;
strudelScope.plain = (v) => {
// console.log('plain', v);
return reify(v);
// return v;
};
// strudelScope.number = (n) => n;
strudelScope.number = reify;
strudelScope.call = (fn, args, name) => {
const [pat, ...rest] = args;
if (!['seq', 'cat', 'stack'].includes(name)) {
args = [...rest, pat];
}
// console.log('call', name, ...flipped);
return fn(...args);
};
strudelScope['*'] = fast;
strudelScope['/'] = slow;
export function mondo(code, offset = 0) {
if (Array.isArray(code)) {
code = code.join('');
}
const pat = runner.run(code, { pipepost: true });
return pat;
}
+42
View File
@@ -0,0 +1,42 @@
{
"name": "@strudel/mondough",
"version": "1.1.0",
"description": "mondo notation for strudel",
"main": "mondough.mjs",
"type": "module",
"publishConfig": {
"main": "dist/mondough.mjs"
},
"scripts": {
"test": "vitest run",
"bench": "vitest bench",
"build:parser": "peggy -o krill-parser.js --format es ./krill.pegjs",
"build": "vite build",
"prepublishOnly": "npm run build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/tidalcycles/strudel.git"
},
"keywords": [
"tidalcycles",
"strudel",
"pattern",
"livecoding",
"algorave"
],
"author": "Felix Roos <flix91@gmail.com>",
"license": "AGPL-3.0-or-later",
"bugs": {
"url": "https://github.com/tidalcycles/strudel/issues"
},
"homepage": "https://github.com/tidalcycles/strudel#readme",
"dependencies": {
"@strudel/core": "workspace:*"
},
"devDependencies": {
"mondo": "*",
"vite": "^6.0.11",
"vitest": "^3.0.4"
}
}
+19
View File
@@ -0,0 +1,19 @@
import { defineConfig } from 'vite';
//import { dependencies } from './package.json';
import { resolve } from 'path';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [],
build: {
lib: {
entry: resolve(__dirname, 'mondough.mjs'),
formats: ['es'],
fileName: (ext) => ({ es: 'mondough.mjs' })[ext],
},
rollupOptions: {
// external: [...Object.keys(dependencies)],
},
target: 'esnext',
},
});
+103
View File
@@ -353,6 +353,22 @@ importers:
specifier: ^3.0.4
version: 3.0.4(@types/debug@4.1.12)(@types/node@22.10.10)(@vitest/ui@3.0.4)(jiti@2.4.2)(lightningcss@1.29.1)(terser@5.37.0)(yaml@2.7.0)
packages/mondough:
dependencies:
'@strudel/core':
specifier: workspace:*
version: link:../core
devDependencies:
mondo:
specifier: '*'
version: 0.4.4
vite:
specifier: ^6.0.11
version: 6.0.11(@types/node@22.10.10)(jiti@2.4.2)(lightningcss@1.29.1)(terser@5.37.0)(yaml@2.7.0)
vitest:
specifier: ^3.0.4
version: 3.0.4(@types/debug@4.1.12)(@types/node@22.10.10)(@vitest/ui@3.0.4)(jiti@2.4.2)(lightningcss@1.29.1)(terser@5.37.0)(yaml@2.7.0)
packages/motion:
dependencies:
'@strudel/core':
@@ -674,6 +690,9 @@ importers:
'@strudel/mini':
specifier: workspace:*
version: link:../packages/mini
'@strudel/mondough':
specifier: workspace:*
version: link:../packages/mondough
'@strudel/motion':
specifier: workspace:*
version: link:../packages/motion
@@ -2963,6 +2982,10 @@ packages:
resolution: {integrity: sha512-groO71Fvi5SWpxjI9Ia+chy0QBwT61mg6yxJV27f5YFf+Mw+STT75K6SHySpP8Co5LsCrtsbCH5dJZSRtkSKaQ==}
engines: {node: '>= 14.0.0'}
amdefine@1.0.1:
resolution: {integrity: sha512-S2Hw0TtNkMJhIabBwIojKL9YHO5T0n5eNqWJ7Lrlel/zDbftQpxpapi8tZs3X1HWa+u+QeydGmzzNU0m09+Rcg==}
engines: {node: '>=0.4.2'}
ansi-align@3.0.1:
resolution: {integrity: sha512-IOfwwBF5iczOjp/WeY4YxyjqAFMQoZufdQWDd19SEExbVLNXqvpzSJ/M7Za4/sCPmQ0+GRquoA7bGcINcxew6w==}
@@ -3091,6 +3114,9 @@ packages:
resolution: {integrity: sha512-hsU18Ae8CDTR6Kgu9DYf0EbCr/a5iGL0rytQDobUcdpYOKokk8LEjVphnXkDkgpi0wYVsqrXuP0bZxJaTqdgoA==}
engines: {node: '>= 0.4'}
async@0.2.10:
resolution: {integrity: sha512-eAkdoKxU6/LkKDBzLpT+t6Ff5EtfSF4wx1WfJiPEEV7WNLnDaRXk0oVysiEPm262roaachGexwUv94WhSgN5TQ==}
async@3.2.6:
resolution: {integrity: sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA==}
@@ -3325,6 +3351,9 @@ packages:
claviature@0.1.0:
resolution: {integrity: sha512-Ai12axNwQ7x/F9QAj64RYKsgvi5Y33+X3GUSKAC/9s/adEws8TSSc0efeiqhKNGKBo6rT/c+CSCwSXzXxwxZzQ==}
cldr-plurals@1.0.0:
resolution: {integrity: sha512-xGkehDsjj/ng1LtYiAzdiqDgqTQ/qmWafDlB6R8CfXbpXe4Ge2Tl4l7gxiA+yaD1WCTP3EVfwerdmVwfco7vxw==}
clean-stack@2.2.0:
resolution: {integrity: sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==}
engines: {node: '>=6'}
@@ -4366,6 +4395,9 @@ packages:
resolution: {integrity: sha512-e1LleDykUz2Iu+MTYdkSsuWX8lvAjAcs0Xef0lNIu0S2wOAzuTxCJtcd9S3cijlwYF18EsU3rzb8jPVobxDh9Q==}
engines: {node: '>=16 || 14 >=14.17'}
globalize@0.1.1:
resolution: {integrity: sha512-5e01v8eLGfuQSOvx2MsDMOWS0GFtCx1wPzQSmcHw4hkxFzrQDBO3Xwg/m8Hr/7qXMrHeOIE29qWVzyv06u1TZA==}
globals@11.12.0:
resolution: {integrity: sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==}
engines: {node: '>=4'}
@@ -4427,6 +4459,11 @@ packages:
h3@1.14.0:
resolution: {integrity: sha512-ao22eiONdgelqcnknw0iD645qW0s9NnrJHr5OBz4WOMdBdycfSas1EQf1wXRsm+PcB2Yoj43pjBPwqIpJQTeWg==}
handlebars@1.1.2:
resolution: {integrity: sha512-6lekK3aSHE7XnEqEs+JWQJRSRdCqJYHEVjEfWWZv9pjLUYZNeP26EtlgOrpDCSX+k5N1m74urTbztgBOCko1Kg==}
engines: {node: '>=0.4.7'}
hasBin: true
handlebars@4.7.8:
resolution: {integrity: sha512-vafaFqs8MZkRrSX7sFVUdo3ap/eNiLnb4IakshzvP56X5Nr1iGKAIqdX6tMlm6HcNRIkr6AxO5jFEoJzzpT8aQ==}
engines: {node: '>=0.4.7'}
@@ -5574,6 +5611,10 @@ packages:
engines: {node: '>=18'}
hasBin: true
mondo@0.4.4:
resolution: {integrity: sha512-3ot6iKwC9KZvwmyZ9dgPCnlt0O1GuBnK8QZyhnoJdtkIiRL9X/cmQuu88CbFSznQx6bq19xQdwJHpv8hggH62Q==}
deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
mrmime@2.0.0:
resolution: {integrity: sha512-eu38+hdgojoyq63s+yTpN4XMBdt5l8HhMhc4VKLO9KM5caLIBvUm4thi7fFaxyTmCKeNnXZ5pAlBwCUnhA09uw==}
engines: {node: '>=10'}
@@ -5815,6 +5856,9 @@ packages:
resolution: {integrity: sha512-7x81NCL719oNbsq/3mh+hVrAWmFuEYUqrq/Iw3kUzH8ReypT9QQ0BLoJS7/G9k6N81XjW4qHWtjWwe/9eLy1EQ==}
engines: {node: '>=12'}
optimist@0.3.7:
resolution: {integrity: sha512-TCx0dXQzVtSCg2OgY/bO9hjM9cV4XYx09TVK+s3+FhkjT6LovsLe+pPMzpWf+6yXK/hUizs2gUoTw3jHM0VaTQ==}
optionator@0.9.4:
resolution: {integrity: sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g==}
engines: {node: '>= 0.8.0'}
@@ -6713,6 +6757,10 @@ packages:
source-map-support@0.5.21:
resolution: {integrity: sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==}
source-map@0.1.43:
resolution: {integrity: sha512-VtCvB9SIQhk3aF6h+N85EaqIaBFIAfZ9Cu+NJHHVvc8BbEcnvDcFw6sqQ2dQrT6SlOrZq3tIvyD9+EGq/lJryQ==}
engines: {node: '>=0.8.0'}
source-map@0.5.7:
resolution: {integrity: sha512-LbrmJOMUSdEVxIKvdcJzQC+nQhe8FUZQTXQy6+I75skNgn3OoQ0DZA8YnFa7gp8tqtL3KPf1kmo0R5DoApeSGQ==}
engines: {node: '>=0.10.0'}
@@ -7143,6 +7191,11 @@ packages:
ufo@1.5.4:
resolution: {integrity: sha512-UsUk3byDzKd04EyoZ7U4DOlxQaD14JUKQl6/P7wiX4FNvUfm3XL246n9W5AmqwW5RSFJ27NAuM0iLscAOYUiGQ==}
uglify-js@2.3.6:
resolution: {integrity: sha512-T2LWWydxf5+Btpb0S/Gg/yKFmYjnX9jtQ4mdN9YRq73BhN21EhU0Dvw3wYDLqd3TooGUJlCKf3Gfyjjy/RTcWA==}
engines: {node: '>=0.4.0'}
hasBin: true
uglify-js@3.19.3:
resolution: {integrity: sha512-v3Xu+yuwBXisp6QYTcH4UbH+xYJXqnq2m/LtQVWKWzYc1iehYnLixoQDN9FH6/j9/oybfd6W9Ghwkl8+UMKTKQ==}
engines: {node: '>=0.8.0'}
@@ -7161,6 +7214,9 @@ packages:
underscore@1.13.7:
resolution: {integrity: sha512-GMXzWtsc57XAtguZgaQViUOzs0KTkk8ojr3/xAxXLITqf/3EMwxC0inyETfDFjH/Krbhuep0HNbbjI9i/q3F3g==}
underscore@1.5.2:
resolution: {integrity: sha512-yejOFsRnTJs0N9CK5Apzf6maDO2djxGoLLrlZlvGs2o9ZQuhIhDL18rtFyy4FBIbOkzA6+4hDgXbgz5EvDQCXQ==}
undici-types@6.20.0:
resolution: {integrity: sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==}
@@ -7543,6 +7599,10 @@ packages:
resolution: {integrity: sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==}
engines: {node: '>=0.10.0'}
wordwrap@0.0.3:
resolution: {integrity: sha512-1tMA907+V4QmxV7dbRvb4/8MaRALK6q9Abid3ndMYnbyo8piisCmeONVqVSXqQA3KaP4SLt5b7ud6E2sqP8TFw==}
engines: {node: '>=0.4.0'}
wordwrap@1.0.0:
resolution: {integrity: sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==}
@@ -10426,6 +10486,9 @@ snapshots:
'@algolia/requester-fetch': 5.20.0
'@algolia/requester-node-http': 5.20.0
amdefine@1.0.1:
optional: true
ansi-align@3.0.1:
dependencies:
string-width: 4.2.3
@@ -10635,6 +10698,9 @@ snapshots:
async-function@1.0.0: {}
async@0.2.10:
optional: true
async@3.2.6: {}
asynckit@0.4.0: {}
@@ -10892,6 +10958,8 @@ snapshots:
claviature@0.1.0: {}
cldr-plurals@1.0.0: {}
clean-stack@2.2.0: {}
cli-boxes@3.0.0: {}
@@ -12034,6 +12102,8 @@ snapshots:
minipass: 4.2.8
path-scurry: 1.11.1
globalize@0.1.1: {}
globals@11.12.0: {}
globals@14.0.0: {}
@@ -12100,6 +12170,12 @@ snapshots:
uncrypto: 0.1.3
unenv: 1.10.0
handlebars@1.1.2:
dependencies:
optimist: 0.3.7
optionalDependencies:
uglify-js: 2.3.6
handlebars@4.7.8:
dependencies:
minimist: 1.2.8
@@ -13683,6 +13759,13 @@ snapshots:
requirejs: 2.3.7
requirejs-config-file: 4.0.0
mondo@0.4.4:
dependencies:
cldr-plurals: 1.0.0
globalize: 0.1.1
handlebars: 1.1.2
underscore: 1.5.2
mrmime@2.0.0: {}
ms@2.0.0: {}
@@ -13975,6 +14058,10 @@ snapshots:
is-docker: 2.2.1
is-wsl: 2.2.0
optimist@0.3.7:
dependencies:
wordwrap: 0.0.3
optionator@0.9.4:
dependencies:
deep-is: 0.1.4
@@ -15082,6 +15169,11 @@ snapshots:
buffer-from: 1.1.2
source-map: 0.6.1
source-map@0.1.43:
dependencies:
amdefine: 1.0.1
optional: true
source-map@0.5.7: {}
source-map@0.6.1: {}
@@ -15549,6 +15641,13 @@ snapshots:
ufo@1.5.4: {}
uglify-js@2.3.6:
dependencies:
async: 0.2.10
optimist: 0.3.7
source-map: 0.1.43
optional: true
uglify-js@3.19.3:
optional: true
@@ -15565,6 +15664,8 @@ snapshots:
underscore@1.13.7: {}
underscore@1.5.2: {}
undici-types@6.20.0: {}
unenv@1.10.0:
@@ -15945,6 +16046,8 @@ snapshots:
word-wrap@1.2.5: {}
wordwrap@0.0.3: {}
wordwrap@1.0.0: {}
workbox-background-sync@7.0.0:
+1
View File
@@ -42,6 +42,7 @@
"@strudel/tonal": "workspace:*",
"@strudel/transpiler": "workspace:*",
"@strudel/webaudio": "workspace:*",
"@strudel/mondough": "workspace:*",
"@strudel/xen": "workspace:*",
"@supabase/supabase-js": "^2.48.1",
"@tailwindcss/forms": "^0.5.10",
+1
View File
@@ -84,6 +84,7 @@ export function loadModules() {
import('@strudel/gamepad'),
import('@strudel/motion'),
import('@strudel/mqtt'),
import('@strudel/mondough'),
];
if (isTauri()) {
modules = modules.concat([