Skip to content
Snippets Groups Projects
Commit 822e6c4d authored by Taddeus Kroes's avatar Taddeus Kroes
Browse files

Validation not uses new 'clone' function.

parent d86dda92
No related branches found
No related tags found
No related merge requests found
from src.parser import Parser
from parser import Parser
from possibilities import apply_suggestion
from strategy import find_possibilities
from tests.parser import ParserWrapper
from src.possibilities import apply_suggestion
def validate(exp, result):
......@@ -8,25 +9,21 @@ def validate(exp, result):
Validate that exp =>* result.
"""
parser = ParserWrapper(Parser)
exp = parser.run([exp])
result = parser.run([result])
return traverse_preorder(parser, exp, result)
def traverse_preorder(node, result):
if node.equals(result):
return True
for p in find_possibilities(node):
# Clone the root node because it will be used in multiple
# substitutions
child = apply_suggestion(node.clone(), p)
def traverse_preorder(parser, exp, result):
"""
Traverse the possibility tree using pre-order traversal.
"""
root = parser.run([exp])
if root.equals(result):
return root
possibilities = parser.parser.possibilities
if traverse_preorder(child, result):
return True
for p in possibilities:
child = apply_suggestion(root, p)
next_root = traverse_preorder(parser, str(child), result)
return False
if next_root:
return next_root
return traverse_preorder(exp, result)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment