Improved dispatchers with richer results and added predicate and regular expression based dispatchers

This commit is contained in:
2026-04-12 19:12:00 +02:00
parent 225990b22d
commit cf1abadfc9
8 changed files with 173 additions and 28 deletions

View File

@@ -0,0 +1,36 @@
import * as CF from '@efforting.tech/data/field-configuration-factories';
import { inspect } from 'node:util';
import { Text_Tree_Node, Text_Tree_Settings } from '@efforting.tech/text/basic-tree';
import { RegExp_Resolver } from '@efforting.tech/rule-processing/resolvers';
const ts = Text_Tree_Settings.load({
text: {
indention_mode: 'TABULATORS',
},
trim_lines: true,
});
const example_string =
`
animals: dog, cat
trees: birch, pine
`;
const root = Text_Tree_Node.from_string(ts, example_string);
const d = new RegExp_Resolver([
[/^animals:\s*(.*)$/, (c) => console.log("ANIMAL", c)],
[/^trees:\s*(.*)$/, () => console.log("TREE")],
]);
for (const child of root.children) {
if (child.has_line) {
console.log(child.line, d.resolve(child.line));
}
}