|
@@ -80,7 +80,7 @@ def _consume_to_end():
|
|
|
class ModelverseException(Exception):
|
|
|
pass
|
|
|
|
|
|
-class UnknownError(ModelverseException):
|
|
|
+class UnknownException(ModelverseException):
|
|
|
pass
|
|
|
|
|
|
class UnknownIdentifier(ModelverseException):
|
|
@@ -158,7 +158,7 @@ def register(username, password):
|
|
|
_consume_to_end()
|
|
|
mode = 2
|
|
|
|
|
|
-def model_add(model_name, metamodel_name, model_code):
|
|
|
+def model_add(model_name, metamodel_name, model_code=None):
|
|
|
"""Instantiate a new model."""
|
|
|
# return None
|
|
|
# raises UnknownModel
|
|
@@ -176,7 +176,10 @@ def model_add(model_name, metamodel_name, model_code):
|
|
|
_input(model_name)
|
|
|
if _output() == "Waiting for model constructors...":
|
|
|
try:
|
|
|
- _compile_model(model_code)
|
|
|
+ if model_code == None:
|
|
|
+ _input("exit")
|
|
|
+ else:
|
|
|
+ _compile_model(model_code)
|
|
|
except Exception:
|
|
|
raise CompilationError()
|
|
|
_consume_to_end()
|
|
@@ -369,7 +372,7 @@ def read_attrs(ID):
|
|
|
r = _last_output()
|
|
|
key, value = r.split(":")
|
|
|
_, value = value.split("=")
|
|
|
- key = key.strip()
|
|
|
+ key = json.loads(key.strip())
|
|
|
value = value.strip()
|
|
|
value = None if value == "None" else json.loads(value)
|
|
|
rval[key] = value
|
|
@@ -381,14 +384,52 @@ def instantiate(typename, edge=None, ID=""):
|
|
|
# raises UnknownError
|
|
|
# raises UnknownType
|
|
|
# raises UnknownIdentifier
|
|
|
+ # raises NotAnEdge
|
|
|
if mode != 3:
|
|
|
raise InvalidMode()
|
|
|
_input("instantiate")
|
|
|
- _input(typename)
|
|
|
- _input(ID)
|
|
|
- if (edge is not None):
|
|
|
- _input(edge[0])
|
|
|
- _input(edge[1])
|
|
|
+ if (_output() == "Permission denied"):
|
|
|
+ _consume_to_end()
|
|
|
+ raise PermissionDenied()
|
|
|
+ else:
|
|
|
+ _input(typename)
|
|
|
+ if (_output() == "Name of new element?"):
|
|
|
+ _input(ID)
|
|
|
+ if (_output() == "Element already exists; aborting"):
|
|
|
+ _consume_to_end()
|
|
|
+ raise ElementExists()
|
|
|
+
|
|
|
+ if (edge is not None):
|
|
|
+ if (_last_output() == "Source name?"):
|
|
|
+ _input(edge[0])
|
|
|
+ if (_output() != "Destination name?"):
|
|
|
+ _consume_to_end()
|
|
|
+ raise UnknownIdentifier()
|
|
|
+ _input(edge[1])
|
|
|
+ ID = _output()
|
|
|
+ if (ID == "Unknown destination; aborting"):
|
|
|
+ _consume_to_end()
|
|
|
+ raise UnknownIdentifier()
|
|
|
+ else:
|
|
|
+ _consume_to_end()
|
|
|
+ return ID
|
|
|
+ else:
|
|
|
+ _consume_to_end()
|
|
|
+ raise NotAnEdge()
|
|
|
+ else:
|
|
|
+ ID = _last_output()
|
|
|
+ _consume_to_end()
|
|
|
+ return ID
|
|
|
+
|
|
|
+ elif (_last_output() == "Permission denied"):
|
|
|
+ _consume_to_end()
|
|
|
+ raise PermissionDenied()
|
|
|
+ elif (_last_output() == "Unknown type specified; aborting"):
|
|
|
+ _consume_to_end()
|
|
|
+ raise UnknownType()
|
|
|
+ else:
|
|
|
+ print(9)
|
|
|
+ print(_last_output())
|
|
|
|
|
|
def delete(ID):
|
|
|
"""Delete the element with the given ID"""
|
|
@@ -478,6 +519,7 @@ def model_exit():
|
|
|
if mode != 3:
|
|
|
raise InvalidMode()
|
|
|
_input("exit")
|
|
|
+ _consume_to_end()
|
|
|
mode = 2
|
|
|
|
|
|
def transformation_add_MT_language():
|