WIP - reduction system
This commit is contained in:
@@ -83,14 +83,14 @@ export class Parser {
|
||||
this.switch_to(tokenizer);
|
||||
}
|
||||
|
||||
leave_sub_tokenizer() {
|
||||
leave_sub_tokenizer(egress_match=null) {
|
||||
const frame = this.stack.pop(true);
|
||||
const { sub_tokenizer_handlers } = this.state;
|
||||
|
||||
if (sub_tokenizer_handlers.length) {
|
||||
const handler = sub_tokenizer_handlers.pop();
|
||||
this.state.match = null; //TODO: Decide if we should reset match here or not
|
||||
handler(this, frame.value);
|
||||
handler(this, frame.value, egress_match);
|
||||
} else {
|
||||
this.push_token(frame.value);
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user