add rule definition with minimal dsl

This commit is contained in:
JOLIMAITRE Matthieu 2024-08-07 11:59:58 +02:00
parent fa524a5976
commit 084c5a2574
5 changed files with 48 additions and 15 deletions

View file

@ -1,5 +1,5 @@
import { StructOfArr } from "./types.ts";
import { zip } from "./utils.ts";
import { split_once, zip } from "./utils.ts";
export class Rule<V extends string[]> {
private separators: ({ kind: "word", word: string } | { kind: "end" })[];
@ -32,11 +32,3 @@ export class Rule<V extends string[]> {
return result as StructOfArr<V, string>;
}
}
function split_once(text: string, separator: string) {
const cursor = text.indexOf(separator);
if (cursor === -1) return [text, null] as const;
const left = text.slice(0, cursor);
const right = text.slice(cursor + separator.length);
return [left, right] as const;
}