|
@@ -46,7 +46,8 @@ class ModelVisitor(Visitor):
|
|
|
model_type = children[0].get_text()
|
|
|
model_name = children[1].get_text()
|
|
|
self.constructors.extend(["instantiate_model", model_type, model_name])
|
|
|
- self.constructors.extend(["define_inheritance", model_name, "Inheritance"])
|
|
|
+ if "LPAR" in tree.get_tail():
|
|
|
+ self.constructors.extend(["define_inheritance", model_name, tree.get_children("MODEL_ID")[1].get_text()])
|
|
|
self.current_model = model_name
|
|
|
for element in tree.get_children("model_element"):
|
|
|
self.visit(element)
|
|
@@ -75,6 +76,8 @@ class ModelVisitor(Visitor):
|
|
|
for attr in tree.get_children("model_attribute"):
|
|
|
self.visit(attr)
|
|
|
|
|
|
+ return element_name
|
|
|
+
|
|
|
def visit_inheritance(self, tree):
|
|
|
for token in tree.get_children("MODEL_ID"):
|
|
|
superclass = token.get_text()
|
|
@@ -85,6 +88,7 @@ class ModelVisitor(Visitor):
|
|
|
is_definition = bool(tree.get_children("COLON"))
|
|
|
is_constraint = bool(tree.get_children("DOLLAR"))
|
|
|
is_assign = bool(tree.get_children("model_attr_instance"))
|
|
|
+ is_nested = bool(tree.get_children("model_element"))
|
|
|
|
|
|
if is_definition:
|
|
|
attr_name = children[0].get_text()
|
|
@@ -116,21 +120,51 @@ class ModelVisitor(Visitor):
|
|
|
directory = os.path.realpath(__file__).rsplit(os.sep, 1)[0]
|
|
|
compiled = do_compile(".constraint.alc", directory + "/../grammars/actionlanguage.g", "CS")
|
|
|
self.constructors.extend(["add_constraint", self.current_model, self.current_element] + compiled)
|
|
|
+ elif is_nested:
|
|
|
+ if tree.get_children("MODEL_ID"):
|
|
|
+ contains_link = tree.get_children("MODEL_ID")[0].get_text()
|
|
|
+ else:
|
|
|
+ contains_link = ""
|
|
|
+ entry = self.visit(tree.get_children("model_element")[0])
|
|
|
+ self.constructors.extend(["instantiate_link", self.current_model, contains_link, "__%s" % self.free_id, self.current_element, entry])
|
|
|
+ self.free_id += 1
|
|
|
|
|
|
def visit_model_attr_instance(self, tree):
|
|
|
+ def constructors_compile(code):
|
|
|
+ code_fragments = code.split("\n")
|
|
|
+ code_fragments = [i for i in code_fragments if i.strip() != ""]
|
|
|
+ code_fragments = [i.replace(" ", "\t") for i in code_fragments]
|
|
|
+ initial_tabs = min([len(i) - len(i.lstrip("\t")) for i in code_fragments])
|
|
|
+ code_fragments = [i[initial_tabs:] for i in code_fragments]
|
|
|
+ code = "\n".join(code_fragments)
|
|
|
+
|
|
|
+ with open(".code.alc", 'w') as f:
|
|
|
+ f.write(code)
|
|
|
+ f.flush()
|
|
|
+ directory = os.path.realpath(__file__).rsplit(os.sep, 1)[0]
|
|
|
+ compiled = do_compile(".code.alc", directory + "/../grammars/actionlanguage.g", "CS")
|
|
|
+
|
|
|
children = tree.get_children("MODEL_ID")
|
|
|
attr_name = children[0].get_text()
|
|
|
- attr_value = tree.get_children("value")[0].get_tail()[0]
|
|
|
- if attr_value.head == "STRVALUE":
|
|
|
- attr_value = attr_value.get_text()[1:-1]
|
|
|
- elif attr_value.head == "TRUE":
|
|
|
- attr_value = True
|
|
|
- elif attr_value.head == "FALSE":
|
|
|
- attr_value = False
|
|
|
- elif attr_value.head == "DEC_NUMBER":
|
|
|
- attr_value = int(attr_value.get_text())
|
|
|
- elif attr_value.head == "FLOAT_NUMBER":
|
|
|
- attr_value = float(attr_value.get_text())
|
|
|
+ if tree.get_children("value"):
|
|
|
+ # Value attribute
|
|
|
+ attr_value = tree.get_children("value")[0].get_tail()[0]
|
|
|
+ if attr_value.head == "STRVALUE":
|
|
|
+ attr_value = attr_value.get_text()[1:-1]
|
|
|
+ elif attr_value.head == "TRUE":
|
|
|
+ attr_value = True
|
|
|
+ elif attr_value.head == "FALSE":
|
|
|
+ attr_value = False
|
|
|
+ elif attr_value.head == "DEC_NUMBER":
|
|
|
+ attr_value = int(attr_value.get_text())
|
|
|
+ elif attr_value.head == "FLOAT_NUMBER":
|
|
|
+ attr_value = float(attr_value.get_text())
|
|
|
+ else:
|
|
|
+ raise Exception(attr_value.head)
|
|
|
+ self.constructors.extend(["instantiate_attribute", self.current_model, self.current_element, attr_name, attr_value])
|
|
|
+ elif tree.get_children("DOLLAR"):
|
|
|
+ # Coded attribute
|
|
|
+ self.constructors.extend(["instantiate_attribute_code", self.current_model, self.current_element, attr_name, constructors_compile(tree.get_children("ANYTHING_EXCEPT_DOLLAR")[1].get_text())])
|
|
|
else:
|
|
|
- raise Exception(attr_value.head)
|
|
|
- self.constructors.extend(["instantiate_attribute", self.current_model, self.current_element, attr_name, attr_value])
|
|
|
+ # Assign direct reference
|
|
|
+ self.constructors.extend(["instantiate_attribute_ref", self.current_model, self.current_element, attr_name, tree.get_children("MODEL_ID")[1].get_text()])
|