mirror of
https://github.com/eliasstepanik/strudel.git
synced 2026-01-14 23:28:34 +00:00
35 lines
733 B
TypeScript
35 lines
733 B
TypeScript
import * as krill from '../krill-parser';
|
|
import * as strudel from '../../strudel.mjs';
|
|
|
|
export function patternifyAST(ast: any): any {
|
|
switch (ast.type_) {
|
|
case 'pattern':
|
|
return strudel.sequence(...ast.source_.map(patternifyAST));
|
|
case 'element':
|
|
if (typeof ast.source_ !== 'object') {
|
|
return ast.source_;
|
|
}
|
|
return patternifyAST(ast.source_);
|
|
}
|
|
}
|
|
export default (str: string) => patternifyAST(krill.parse(`"${str}"`));
|
|
|
|
/*
|
|
TODO:
|
|
export interface Arguments {
|
|
alignment: string;
|
|
}
|
|
|
|
export interface ElementStub {
|
|
type_: string;
|
|
source_: string;
|
|
options_?: any;
|
|
}
|
|
|
|
export interface PatternStub {
|
|
type_: string; // pattern
|
|
arguments_: Arguments;
|
|
source_: ElementStub[];
|
|
}
|
|
*/
|