Skip to content

Instantly share code, notes, and snippets.

@metaweta
Created October 9, 2013 06:10
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 metaweta/6896915 to your computer and use it in GitHub Desktop.
Save metaweta/6896915 to your computer and use it in GitHub Desktop.
class TagTree {
static function render(tree: Dynamic): String {
var result: Array<String> = [];
var keys: Array<String> = untyped (Object.keys(tree));
for (i in keys) {
var child: Dynamic = untyped tree[i];
if (untyped child._visited) {
untyped __js__("delete child._visited");
var childStr = render(child);
result.push(
"v" + i + "(" +
(childStr == "_" ? "_" : "[" + childStr + "]") +
")"
);
} else {
result.push("_");
}
}
result.push("_");
return result.join(" | ");
}
public static function toProlog(tree: Dynamic, paths: Array<Array<String>>): String {
var i: Int;
for (i in 0 ... paths.length) {
var p: Dynamic = tree;
var j: Int;
for (j in 0 ... paths[i].length) {
p = untyped p[paths[i][j]];
p._visited = true;
}
}
var childStr = render(tree);
return "and(" + (childStr == "_" ? "_" : "[" + childStr + "]") + ")";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment