Created
October 9, 2013 06:10
-
-
Save metaweta/6896915 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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