|
@@ -1,6 +1,7 @@
|
|
|
include "primitives.alh"
|
|
|
include "modelling.alh"
|
|
|
include "object_operations.alh"
|
|
|
+include "random.alh"
|
|
|
|
|
|
Boolean function main(model : Element):
|
|
|
String result
|
|
@@ -16,7 +17,9 @@ Boolean function main(model : Element):
|
|
|
Element rules
|
|
|
String rule
|
|
|
String value
|
|
|
+ Element explored
|
|
|
|
|
|
+ explored = set_create()
|
|
|
result = "root, = yield [('RR', [])]\n"
|
|
|
nodes = allInstances(model, "Rules/Root")
|
|
|
while (set_len(nodes) > 0):
|
|
@@ -41,16 +44,27 @@ Boolean function main(model : Element):
|
|
|
// Is a match node, so fetch the value on the edge
|
|
|
name = read_attribute(model, edge, "value")
|
|
|
destination = string_replace(new_node, "/", "_")
|
|
|
- result = result + destination + ", = yield [('RD', [" + source + ", " + name + "])]\n"
|
|
|
+ if (set_in(explored, destination)):
|
|
|
+ // Already visited this one in another way, so try to merge!
|
|
|
+ String rand
|
|
|
+ rand = random_string(10)
|
|
|
+ result = result + rand + ", = yield [('RD', [" + source + ", " + name + "])]\n"
|
|
|
+ result = result + "if " + rand + " != " + destination + ":\n"
|
|
|
+ // If the values don't agree, this is not a correct match, and we say that this element remains unmatched (i.e., assign None)
|
|
|
+ result = result + "\t" + destination + " = None\n"
|
|
|
+ else:
|
|
|
+ // First visit to this element, so just assign
|
|
|
+ result = result + destination + ", = yield [('RD', [" + source + ", " + name + "])]\n"
|
|
|
+ set_add(explored, destination)
|
|
|
|
|
|
- String value
|
|
|
- value = read_attribute(model, new_node, "value")
|
|
|
- if (element_neq(value, read_root())):
|
|
|
- // Match node has a value we should compare as well!
|
|
|
- // Read out the value from the Modelverse
|
|
|
- result = result + destination + "_V, = yield [('RV', [" + destination + "])]\n"
|
|
|
+ String value
|
|
|
+ value = read_attribute(model, new_node, "value")
|
|
|
+ if (element_neq(value, read_root())):
|
|
|
+ // Match node has a value we should compare as well!
|
|
|
+ // Read out the value from the Modelverse
|
|
|
+ result = result + destination + "_V, = yield [('RV', [" + destination + "])]\n"
|
|
|
|
|
|
- set_add(to_explore, new_node)
|
|
|
+ set_add(to_explore, new_node)
|
|
|
|
|
|
rules = allInstances(model, "Rules/Rule")
|
|
|
while (set_len(rules) > 0):
|