now supporting tidal syntax directly
This commit is contained in:
parent
a00f00a7fe
commit
bc79986dd2
3 changed files with 26 additions and 3 deletions
|
|
@ -24,6 +24,7 @@ synth.set({
|
||||||
});
|
});
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
|
const [mode, setMode] = useState<string>('javascript');
|
||||||
const [code, setCode] = useState<string>(tetrisHaskell);
|
const [code, setCode] = useState<string>(tetrisHaskell);
|
||||||
const [log, setLog] = useState('');
|
const [log, setLog] = useState('');
|
||||||
const logBox = useRef<any>();
|
const logBox = useRef<any>();
|
||||||
|
|
@ -64,7 +65,17 @@ function App() {
|
||||||
// parse pattern when code changes
|
// parse pattern when code changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
try {
|
try {
|
||||||
const _pattern = parse(code);
|
let _pattern;
|
||||||
|
try {
|
||||||
|
_pattern = h(code);
|
||||||
|
setMode('pegjs'); // haskell mode does not recognize quotes, pegjs looks ok by accident..
|
||||||
|
// console.log('h _pattern', _pattern);
|
||||||
|
} catch (err) {
|
||||||
|
setMode('javascript');
|
||||||
|
// code is not haskell like
|
||||||
|
_pattern = parse(code);
|
||||||
|
// console.log('not haskell..', _pattern);
|
||||||
|
}
|
||||||
setPattern(_pattern);
|
setPattern(_pattern);
|
||||||
// cycle.query(cycle.activeCycle()); // reschedule active cycle
|
// cycle.query(cycle.activeCycle()); // reschedule active cycle
|
||||||
setError(undefined);
|
setError(undefined);
|
||||||
|
|
@ -88,6 +99,11 @@ function App() {
|
||||||
<div className={cx('h-full bg-slate-600', error ? 'focus:ring-red-500' : 'focus:ring-slate-800')}>
|
<div className={cx('h-full bg-slate-600', error ? 'focus:ring-red-500' : 'focus:ring-slate-800')}>
|
||||||
<CodeMirror
|
<CodeMirror
|
||||||
value={code}
|
value={code}
|
||||||
|
options={{
|
||||||
|
mode,
|
||||||
|
theme: 'material',
|
||||||
|
lineNumbers: true,
|
||||||
|
}}
|
||||||
onChange={(_: any, __: any, value: any) => {
|
onChange={(_: any, __: any, value: any) => {
|
||||||
setLog((log) => log + `${log ? '\n\n' : ''}✏️ edit\n${code}\n${value}`);
|
setLog((log) => log + `${log ? '\n\n' : ''}✏️ edit\n${code}\n${value}`);
|
||||||
setCode(value);
|
setCode(value);
|
||||||
|
|
@ -110,7 +126,13 @@ function App() {
|
||||||
>
|
>
|
||||||
{cycle.started ? 'pause' : 'play'}
|
{cycle.started ? 'pause' : 'play'}
|
||||||
</button>
|
</button>
|
||||||
<textarea className="grow bg-[#283237] border-0" value={log} readOnly ref={logBox} style={{ fontFamily: 'monospace' }} />
|
<textarea
|
||||||
|
className="grow bg-[#283237] border-0"
|
||||||
|
value={log}
|
||||||
|
readOnly
|
||||||
|
ref={logBox}
|
||||||
|
style={{ fontFamily: 'monospace' }}
|
||||||
|
/>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Controlled as CodeMirror2 } from 'react-codemirror2';
|
import { Controlled as CodeMirror2 } from 'react-codemirror2';
|
||||||
import 'codemirror/mode/javascript/javascript.js';
|
import 'codemirror/mode/javascript/javascript.js';
|
||||||
|
import 'codemirror/mode/pegjs/pegjs.js';
|
||||||
import 'codemirror/theme/material.css';
|
import 'codemirror/theme/material.css';
|
||||||
import 'codemirror/lib/codemirror.css';
|
import 'codemirror/lib/codemirror.css';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -96,6 +96,6 @@ export const mini = (...strings: string[]) => {
|
||||||
// includes haskell style (raw krill parsing)
|
// includes haskell style (raw krill parsing)
|
||||||
export const h = (string: string) => {
|
export const h = (string: string) => {
|
||||||
const ast = krill.parse(string);
|
const ast = krill.parse(string);
|
||||||
console.log('ast', ast);
|
// console.log('ast', ast);
|
||||||
return patternifyAST(ast);
|
return patternifyAST(ast);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue