add rule definition with minimal dsl
This commit is contained in:
parent
fa524a5976
commit
084c5a2574
5 changed files with 48 additions and 15 deletions
10
lib/rule.ts
10
lib/rule.ts
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue