Improved dispatchers with richer results and added predicate and regular expression based dispatchers
This commit is contained in:
36
experiments/text-nodes-dispatch.mjs
Normal file
36
experiments/text-nodes-dispatch.mjs
Normal 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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user