|
@@ -82,17 +82,23 @@ class ModelVisitor(Visitor):
|
|
|
children = tree.get_children("MODEL_ID")
|
|
|
is_definition = bool(tree.get_children("COLON"))
|
|
|
is_constraint = bool(tree.get_children("DOLLAR"))
|
|
|
- is_assign = bool(tree.get_children("ASSIGN"))
|
|
|
+ is_assign = bool(tree.get_children("model_attr_instance"))
|
|
|
|
|
|
if is_definition:
|
|
|
attr_name = children[0].get_text()
|
|
|
attr_type = children[1].get_text()
|
|
|
self.constructors.extend(['"instantiate_link"', jsonstr(self.current_model), jsonstr("Association"), jsonstr(self.current_element + "_" + attr_name), jsonstr(self.current_element), jsonstr(attr_type)])
|
|
|
- self.constructors.extend(['"instantiate_attribute"', jsonstr(self.current_model), jsonstr(self.current_element + "_" + attr_name), jsonstr("name"), jsonstr(attr_name)])
|
|
|
+ full_attribute_name = self.current_element + "_" + attr_name
|
|
|
+ self.constructors.extend(['"instantiate_attribute"', jsonstr(self.current_model), jsonstr(full_attribute_name), jsonstr("name"), jsonstr(attr_name)])
|
|
|
+ if is_assign:
|
|
|
+ # There are also some attributes to set!
|
|
|
+ old_element = self.current_element
|
|
|
+ self.current_element = full_attribute_name
|
|
|
+ for f in tree.get_children("model_attr_instance"):
|
|
|
+ self.visit(f)
|
|
|
+ self.current_element = old_element
|
|
|
elif is_assign:
|
|
|
- attr_name = children[0].get_text()
|
|
|
- attr_value = tree.get_children("value")[0]
|
|
|
- self.constructors.extend(['"instantiate_attribute"', jsonstr(self.current_model), jsonstr(self.current_element), jsonstr(attr_name), jsonstr(attr_value.get_text()) if attr_value.head == "STRVALUE" else attr_value.get_text()])
|
|
|
+ self.visit(tree.get_children("model_attr_instance")[0])
|
|
|
elif is_constraint:
|
|
|
constraint = tree.get_children("ANYTHING_EXCEPT_DOLLAR")[0].get_text()
|
|
|
whitespaces = len(constraint) - len(constraint.lstrip())
|
|
@@ -107,3 +113,9 @@ class ModelVisitor(Visitor):
|
|
|
f.flush()
|
|
|
directory = os.path.realpath(__file__).rsplit(os.sep, 1)[0]
|
|
|
self.constructors.extend(['"add_constraint"', jsonstr(self.current_model), jsonstr(self.current_element)] + do_compile(".constraint.alc", directory + "/../grammars/actionlanguage.g", "CS"))
|
|
|
+
|
|
|
+ def visit_model_attr_instance(self, tree):
|
|
|
+ children = tree.get_children("MODEL_ID")
|
|
|
+ attr_name = children[0].get_text()
|
|
|
+ attr_value = tree.get_children("value")[0]
|
|
|
+ self.constructors.extend(['"instantiate_attribute"', jsonstr(self.current_model), jsonstr(self.current_element), jsonstr(attr_name), jsonstr(attr_value.get_text()) if attr_value.head == "STRVALUE" else attr_value.get_text()])
|