Skip to content

Instantly share code, notes, and snippets.

@BruJu
Created March 28, 2022 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BruJu/440d7fd1d64df8229928c9ba71ce4ed0 to your computer and use it in GitHub Desktop.
Save BruJu/440d7fd1d64df8229928c9ba71ce4ed0 to your computer and use it in GitHub Desktop.
Logic Rule Debug
/* istanbul ignore next */
debugString(): string {
let strRules: string[] = [];
function debugMeta(info: MetaInfo | null): string {
if (info === null) return '.';
return "<< " + termToString(info.target) + " " + info.kind + " " + termToString(info.value) + " >>";
}
function debugLogcRule(rule: LogicRule): string {
let b = "";
if (rule.dataBody === null) {
b += ".";
} else {
b += termToString(rule.dataBody);
}
b += " + " + debugMeta(rule.metaBody) + " = " + debugMeta(rule.metaHead);
return b;
}
for (const [activator, rules] of this.dataPredicateToRules) {
for (const rule of rules) {
strRules.push(
termToString(activator) + " >>> " + debugLogcRule(rule)
);
}
}
for (const [a, b] of Object.entries(this.metaToRules)) {
for (const [activator, rules] of b) {
for (const rule of rules) {
strRules.push(
a + " " + termToString(activator) + " >>> " + debugLogcRule(rule)
);
}
}
}
for (const rule of this.axioms) {
strRules.push(
" >>> " + debugLogcRule(rule)
);
}
return strRules.map(r => "• " + r).join("\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment