WIP - reduction system

This commit is contained in:
2026-05-14 20:19:02 +02:00
parent 3047649372
commit 235e12e7db
5 changed files with 197 additions and 20 deletions

View File

@@ -23,6 +23,8 @@ export const FP_Reduction_Settings = new CF.Schema({
//TODO - we should probably have a pre-defined record shape as argument for actions and such rather than using an ever growing list of positionals or an anonymous Object()
export class Reduction_Scanner {
static settings_schema = Reduction_Settings;
@@ -36,7 +38,7 @@ export class Reduction_Scanner {
}
}
perform_reduction(sequence) {
find_reduction_candidate(sequence) {
const { settings } = this;
switch (settings.reduction_order) {
@@ -44,12 +46,10 @@ export class Reduction_Scanner {
for (const rule of settings.rules) {
const match = rule.match(sequence);
if (match) {
//console.log('RULE_MAJOR', match);
rule.action(this, sequence, match); //TODO: should rule.action be able to add additional checks? Though that probably dillutes responsibility and blurs interfaces
return true;
return { sequence, rule, match };
}
}
return false;
return;
case Reduction_Order.symbols.POSITION_MAJOR:
@@ -68,18 +68,28 @@ export class Reduction_Scanner {
}
if (best_match) {
//console.log('POSITION_MAJOR', best_match)
best_rule.action(this, sequence, best_match); //TODO: should rule.action be able to add additional checks? Though that probably dillutes responsibility and blurs interfaces
return true;
return { sequence, rule: best_rule, match: best_match };
}
return false;
return;
default:
throw new Error(`Unknown reduction order: ${this.reduction_order}`); //TODO: Force invalid configuration error
}
}
perform_reduction(sequence) {
const candidate = this.find_reduction_candidate(sequence);
if (candidate) {
const { sequence, rule, match } = candidate;
//console.log('ACT', match.match)
match.action({ reduction_system: this, rule, sequence, match: match.match });
return true;
} else {
return false;
}
}
clear_transform_state() {