40 lines
952 B
JavaScript
40 lines
952 B
JavaScript
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';
|
|
import { parse_csv } from '@efforting.tech/data/string-utilities';
|
|
|
|
|
|
|
|
|
|
|
|
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*(.*)$/, ({node, predicate_result}) => console.log(`TREE of node at line ${node.line_no}:`, parse_csv(predicate_result[1]))],
|
|
]);
|
|
|
|
for (const child of root.children) {
|
|
if (child.has_line) {
|
|
console.log(child.line, d.resolve(child.line, { node: child }));
|
|
}
|
|
}
|