mondo highlighting
This commit is contained in:
parent
fae59a6bcd
commit
b0da353115
5 changed files with 138 additions and 38 deletions
|
|
@ -1,25 +1,22 @@
|
|||
import { strudelScope, reify, fast, slow, isControlName } from '@strudel/core';
|
||||
import { strudelScope, reify, fast, slow } from '@strudel/core';
|
||||
import { registerLanguage } from '@strudel/transpiler';
|
||||
import { MondoRunner } from '../mondo/mondo.mjs';
|
||||
|
||||
let runner = new MondoRunner(strudelScope, { pipepost: true });
|
||||
let runner = new MondoRunner(strudelScope, { pipepost: true, loc: true });
|
||||
|
||||
//strudelScope.plain = reify;
|
||||
strudelScope.plain = (v) => {
|
||||
// console.log('plain', v);
|
||||
return reify(v);
|
||||
// return v;
|
||||
let getLeaf = (value, token) => {
|
||||
const [from, to] = token.loc;
|
||||
return reify(value).withLoc(from, to);
|
||||
};
|
||||
// strudelScope.number = (n) => n;
|
||||
strudelScope.number = reify;
|
||||
|
||||
strudelScope.plain = getLeaf;
|
||||
strudelScope.number = getLeaf;
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
|
|
@ -30,6 +27,12 @@ export function mondo(code, offset = 0) {
|
|||
if (Array.isArray(code)) {
|
||||
code = code.join('');
|
||||
}
|
||||
const pat = runner.run(code, { pipepost: true });
|
||||
const pat = runner.run(code, offset);
|
||||
return pat;
|
||||
}
|
||||
|
||||
// tell transpiler how to get locations for mondo`` calls
|
||||
registerLanguage('mondo', {
|
||||
getLocations: (code, offset) => runner.parser.get_locations(code, offset),
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,8 @@
|
|||
},
|
||||
"homepage": "https://github.com/tidalcycles/strudel#readme",
|
||||
"dependencies": {
|
||||
"@strudel/core": "workspace:*"
|
||||
"@strudel/core": "workspace:*",
|
||||
"@strudel/transpiler": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mondo": "*",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue