hrithik18k/punck-tscircuit-recreation
A four-layer Eurorack drum/sampler controller PCB built around an STM32H743, dual QSPI flash, PCM5100 stereo DAC, TL074 analog audio circuitry, input clamps, 12V-to-3.3V power regulation, MIDI/USB/SWD connectors, controls, LEDs, and trigger/audio I/O.
- Version
- 1.0.3
- License
- unset
- Stars
- 0
scripts/sexpr.ts
export type S = string | S[]
export function parse(text: string): S[] {
const tokens = text.match(/"(?:\\.|[^"\\])*"|[()]|[^\s()]+/g) ?? []
let i = 0
function read(): S { const t = tokens[i++]; if (t !== '(') return t; const a: S[] = []; while (tokens[i] !== ')') { if (i >= tokens.length) throw Error('Unclosed S-expression'); a.push(read()) }; i++; return a }
return read() as S[]
}
export const emit = (s: S): string => Array.isArray(s) ? '(' + s.map(emit).join(' ') + ')' : s
export const children = (s: S[], tag: string): S[][] => s.filter(x => Array.isArray(x) && x[0] === tag) as S[][]
export const child = (s: S[], tag: string): S[] | undefined => children(s, tag)[0]
export const atom = (s: S | undefined): string => typeof s === 'string' ? s.startsWith('"') ? JSON.parse(s) : s : ''
export function normalize(s: S[], parent = ''): S[] {
return s.filter((x, i) => !(i > 0 && x === 'locked') && !(Array.isArray(x) && ['symbol_instances', 'locked'].includes(x[0] as string))).map(x => {
if (!Array.isArray(x)) return x
if (s[0] === 'gr_circle' && x[0] === 'fill' && x[1] === 'solid') return ['fill', 'yes']
return normalize(x, s[0] as string)
})
}