Prechádzať zdrojové kódy

Added example of pn_interface as well

Yentl Van Tendeloo 8 rokov pred
rodič
commit
fab1f73781

BIN
doc/_build/doctrees/examples.doctree


BIN
doc/_build/html/_images/prompt_pn_interface.png


+ 380 - 0
doc/_build/html/_sources/examples.txt

@@ -75,3 +75,383 @@ This is normal, though in the future the Modelverse will keep running for other
 
 Modelling Server
 ----------------
+
+The simple Fibonacci server is not very relevant to the primary concern of the Modelverse: (meta-)modelling.
+But since we can create whatever kind of server we want, a simple (meta-)modelling server is created.
+The code offers an interface for users to execute modelling operations.
+The interface itself mostly just relays the incoming messages and operations to the internal modelling library.
+
+The full code is seen below::
+
+    include "primitives.alh"
+    include "constructors.alh"
+    include "object_operations.alh"
+    include "library.alh"
+    include "conformance_scd.alh"
+    include "io.alh"
+    include "metamodels.alh"
+    include "modelling.alh"
+    include "compilation_manager.alh"
+
+    Element function model_loaded(model : Element):
+        String cmd
+
+        Element attr_list_pn
+        Element attr_keys_pn
+        String attr_key_pn
+        Element metamodel_element_pn
+        String typename
+        Boolean bottom
+        Element other_metamodel
+
+        bottom = False
+        other_metamodel = create_node()
+        dict_add(other_metamodel, "model", model["model"])
+        dict_add(other_metamodel, "type_mapping", create_node())
+        dict_add(other_metamodel, "metamodel", import_node("models/LTM_bottom"))
+        dict_add(other_metamodel, "inheritance", other_metamodel["metamodel"]["model"]["__Inheritance"])
+
+        output("Model loaded, ready for commands!")
+        output("Use 'help' command for a list of possible commands")
+
+        while (True):
+            output("Please give your command.")
+            cmd = input()
+            if (cmd == "help"):
+                output("Generic model operations:")
+                output("  instantiate -- Create a new model element")
+                output("  delete      -- Delete an existing element")
+                output("  attr_add    -- Add an attribute to an element")
+                output("  attr_del    -- Delete an attribute of an element")
+                output("  constrain   -- Add a constraint function to the model")
+                output("  rename      -- Rename an existing element")
+                output("  modify      -- Modify the attributes of an element")
+                output("  list        -- Prints the list of elements in the model")
+                output("  types       -- Prints the list of elements that can be instantiated")
+                output("  read        -- Prints the current state of a model element")
+                output("  verify      -- Check whether the model conforms to the metamodel")
+                output("  retype      -- Change the type of an element")
+                output("  switch      -- Switch between conformance bottom and the linguistic metamodel")
+                output("  exit        -- Unload the model and go back to the loading prompt")
+            elif (cmd == "exit"):
+                return model!
+            elif (cmd == "instantiate"):
+                String mm_type_name
+                output("Type to instantiate?")
+                mm_type_name = input()
+                if (dict_in(model["metamodel"]["model"], mm_type_name)):
+                    String element_name
+                    output("Name of new element?")
+                    element_name = input()
+                    if (dict_in(model["model"], element_name)):
+                        output("Element already exists; aborting")
+                    else:
+                        if (is_edge(model["metamodel"]["model"][mm_type_name])):
+                            output("Source name?")
+                            String src_name
+                            src_name = input()
+                            if (dict_in(model["model"], src_name)):
+                                output("Destination name?")
+                                String dst_name
+                                dst_name = input()
+                                if (dict_in(model["model"], dst_name)):
+                                    instantiate_link(model, mm_type_name, element_name, src_name, dst_name)
+                                    output("Instantiation successful!")
+                                else:
+                                    output("Unknown destination; aborting")
+                            else:
+                                output("Unknown source; aborting")
+                        else:
+                            instantiate_node(model, mm_type_name, element_name)
+                            output("Instantiation successful!")
+                else:
+                    output("Unknown type specified; aborting")
+            elif (cmd == "set_inheritance"):
+                String inh_name
+
+                output("Which link in the metamodel is the inheritance link?")
+                inh_name = input()
+
+                if (dict_in(model["metamodel"]["model"], inh_name)):
+                    dict_add(model, "inheritance", model["metamodel"]["model"][inh_name])
+                    output("Set inheritance link!")
+                else:
+                    output("Element not found in metamodel; aborting")
+
+            elif (cmd == "constrain"):
+                output("Element to constrain (empty for global)?")
+                String model_name
+                model_name = input()
+
+                if (model_name == ""):
+                    // Global constraint
+                    output("Give input to function constructors for GLOBAL constraint!")
+                    set_model_constraints(model, construct_function())
+                elif (dict_in(model["model"], model_name)):
+                    // Local constraint for this model
+                    output("Give input to function constructors for LOCAL constraint!")
+                    add_constraint(model, model_name, construct_function())
+                    output("Added constraint to model!")
+                else:
+                    // Local constraint, but model not found
+                    output("Unknown model; aborting")
+            elif (cmd == "modify"):
+                String model_name
+                output("Element to modify?")
+                model_name = input()
+                if (dict_in(model["model"], model_name)):
+                    Element attrs
+                    attrs = getAttributeList(model, model_name)
+                    String attr_name
+                    output("Attribute to modify?")
+                    attr_name = input()
+                    if (set_in(dict_keys(attrs), attr_name)):
+                        output("New value?")
+                        unset_attribute(model, model_name, attr_name)
+                        instantiate_attribute(model, model_name, attr_name, input())
+                        output("Modified!")
+                    else:
+                        output("No such attribute!")
+                else:
+                    output("No such model!")
+            elif (cmd == "attr_add"):
+                String model_name
+                output("Which model do you want to assign an attribute to?")
+                model_name = input()
+                if (dict_in(model["model"], model_name)):
+                    Element attrs
+                    attrs = getAttributeList(model, model_name)
+                    String attr_name
+                    output("Which attribute do you wish to assign?")
+                    attr_name = input()
+                    if (set_in(dict_keys(attrs), attr_name)):
+                        output("Value of attribute?")
+                        instantiate_attribute(model, model_name, attr_name, input())
+                        output("Added attribute!")
+                    else:
+                        output("No such attribute!")
+                else:
+                    output("No such model!")
+            elif (cmd == "attr_del"):
+                String model_name
+                output("Which model do you want to remove an attribute of?")
+                model_name = input()
+                if (dict_in(model["model"], model_name)):
+                    Element attrs
+                    attrs = getAttributeList(model, model_name)
+                    String attr_name
+                    output("Which attribute do you want to delete?")
+                    attr_name = input()
+                    if (set_in(dict_keys(attrs), attr_name)):
+                        unset_attribute(model, model_name, attr_name)
+                        output("Attribute deleted!")
+                    else:
+                        output("No such attribute!")
+                else:
+                    output("No such model!")
+            elif (cmd == "delete"):
+                output("What is the name of the element you want to delete?")
+                cmd = input()
+                if (dict_in(model["model"], cmd)):
+                    model_delete_element(model, cmd)
+                    output("Deleted!")
+                else:
+                    output("No such element; aborting")
+            elif (cmd == "rename"):
+                output("Old name?")
+                String old_name_e
+                old_name_e = input()
+                if (dict_in(model["model"], old_name_e)):
+                    output("New name?")
+                    String new_name_e
+                    new_name_e = input()
+                    if (dict_in(model["model"], new_name_e)):
+                        output("New name already used; aborting")
+                    else:
+                        dict_add(model["model"], new_name_e, model["model"][old_name_e])
+                        dict_delete(model["model"], old_name_e)
+                        output("Rename complete!")
+                else:
+                    output("Unknown element; aborting")
+            elif (cmd == "list"):
+                Element keys_m
+                keys_m = dict_keys(model["model"])
+                output("List of all elements:")
+                String v_m
+                while (read_nr_out(keys_m) > 0):
+                    v_m = set_pop(keys_m)
+                    // Filter out anonymous objects
+                    if (bool_not(string_startswith(v_m, "__"))):
+                        typename = reverseKeyLookup(model["metamodel"]["model"], dict_read_node(model["type_mapping"], model["model"][v_m]))
+                        output((("  " + v_m) + " : ") + typename)
+            elif (cmd == "read"):
+                output("Element to read?")
+                cmd = input()
+                if (dict_in(model["model"], cmd)):
+                    Element read_elem
+                    read_elem = model["model"][cmd]
+                    metamodel_element_pn = dict_read_node(model["type_mapping"], read_elem)
+
+                    output("Name: " + cmd)
+                    output("Type: " + reverseKeyLookup(model["metamodel"]["model"], metamodel_element_pn))
+                    if (is_edge(read_elem)):
+                        output("Source: " + reverseKeyLookup(model["model"], read_edge_src(read_elem)))
+                        output("Destination: " + reverseKeyLookup(model["model"], read_edge_dst(read_elem)))
+                    if (cast_v2s(read_elem) != "None"):
+                        output("Value: " + cast_v2s(read_elem))
+                    output("Defines attributes:")
+                    attr_list_pn = getInstantiatableAttributes(model, read_elem)
+                    attr_keys_pn = dict_keys(attr_list_pn)
+                    while (0 < read_nr_out(attr_keys_pn)):
+                        attr_key_pn = set_pop(attr_keys_pn)
+                        output(((("  " + attr_key_pn) + " : ") + cast_v2s(attr_list_pn[attr_key_pn])))
+                    output("Attributes:")
+                    attr_list_pn = getAttributeList(model, cmd)
+                    attr_keys_pn = dict_keys(attr_list_pn)
+                    while (0 < read_nr_out(attr_keys_pn)):
+                        attr_key_pn = set_pop(attr_keys_pn)
+                        output((((("  " + cast_v2s(attr_key_pn)) + " : ") + cast_v2s(attr_list_pn[attr_key_pn])) + " = ") + cast_v2s(read_attribute(model, reverseKeyLookup(model["model"], read_elem), attr_key_pn)))
+                else:
+                    output("Unknown element; aborting")
+            elif (cmd == "verify"):
+                output(conformance_scd(model))
+            elif (cmd == "types"):
+                Element keys_t
+                keys_t = dict_keys(model["metamodel"]["model"])
+                output("List of types:")
+                String v_t
+                while (read_nr_out(keys_t) > 0):
+                    v_t = set_pop(keys_t)
+                    if (bool_not(string_startswith(v_t, "__"))):
+                        output(string_join(("  " + v_t) + " : ", reverseKeyLookup(model["metamodel"]["metamodel"]["model"], dict_read_node(model["metamodel"]["type_mapping"], model["metamodel"]["model"][v_t]))))
+            elif (cmd == "retype"):
+                output("Element to retype?")
+                String elementname
+                elementname = input()
+                if (dict_in(model["model"], elementname)):
+                    output("New type")
+                    typename = input()
+                    if (dict_in(model["metamodel"]["model"], typename)):
+                        // OK, do the retyping
+                        // First try removing the previous type if it exists
+                        dict_delete(model["type_mapping"], model["model"][elementname])
+                        // Now add the new type
+                        dict_add(model["type_mapping"], model["model"][elementname], model["metamodel"]["model"][typename])
+                        output("Retyped!")
+                    else:
+                        output("Unknown type; aborting")
+                else:
+                    output("Unknown element; aborting")
+            elif (cmd == "switch"):
+                bottom = bool_not(bottom)
+
+                Element tmp_model
+                tmp_model = model
+                model = other_metamodel
+                other_metamodel = tmp_model
+
+                if (bottom):
+                    // The type mapping we are using is probably not complete for our model
+                    // so we completely recreate it from the model we have.
+                    output("Switching to conformance bottom mode!")
+                    generate_bottom_type_mapping(model)
+                else:
+                    // We already switched the models and such, so we are already done!
+                    output("Switching to linguistic metamodel!")
+            else:
+                output("Unknown command: " + cast_v2s(cmd))
+                output("Use command 'help' to get a list of available commands")
+
+    Element function main():
+        output("Welcome to the Model Management Interface, running live on the Modelverse!")
+        output("Use 'help' command for a list of possible commands")
+        String command
+        Element root
+        Element metamodel
+        String name
+        Element my_model
+        String mm_name
+
+        root = create_metamodels()
+
+        while (True):
+            output("Please give your command.")
+            command = input()
+
+            if (command == "help"):
+                output("Currently no model is loaded, so your operations are limited to:")
+                output("  new    -- Create a new model and save it for future use")
+                output("  load   -- Load a previously made model")
+                output("  rename -- Rename a previously made model")
+                output("  delete -- Delete a previously made model")
+                output("  list   -- Show a list of all stored models")
+                output("  help   -- Show a list of possible commands")
+            elif (command == "new"):
+                output("Metamodel to instantiate?")
+                mm_name = input()
+                if (dict_in(root, mm_name)):
+                    output("Name of model?")
+                    name = input()
+                    if (dict_in(root, name)):
+                        output("Model exists; aborting")
+                    else:
+                        my_model = instantiate_model(root[mm_name])
+                        dict_add(root, name, my_model)
+                        model_loaded(my_model)
+                else:
+                    output("Unknown metamodel; aborting")
+            elif (command == "load"):
+                output("Model to load?")
+                name = input()
+                if (dict_in(root, name)):
+                    my_model = root[name]
+                    model_loaded(my_model)
+                else:
+                    output("Model not found; aborting")
+            elif (command == "list"):
+                Element keys
+                String m_menu_list
+                keys = dict_keys(root)
+                output("Found models:")
+                while (read_nr_out(keys) > 0):
+                    m_menu_list = set_pop(keys)
+                    output((("  " + m_menu_list) + " : ") + reverseKeyLookup(root, root[m_menu_list]["metamodel"]))
+            elif (command == "delete"):
+                output("Model to delete?")
+                name = input()
+                if (dict_in(root, name)):
+                    dict_delete(root, name)
+                    output("Deleted!")
+                else:
+                    output("Model not found; aborting")
+            elif (command == "rename"):
+                output("Old name?")
+                String old_name
+                old_name = input()
+                if (dict_in(root, old_name)):
+                    output("New name?")
+                    String new_name
+                    new_name = input()
+                    if (dict_in(root, new_name)):
+                        output("Model exists; aborting")
+                    else:
+                        dict_add(root, new_name, root[old_name])
+                        dict_delete(root, old_name)
+                        output("Rename complete!")
+                else:
+                    output("Model not found; aborting")
+            elif (command == "actions"):
+                output("Switching to compilation manager!")
+                compilation_manager()
+                output("Back in model manager!")
+            else:
+                output("Command not recognized, use 'help' for a list of possible commands")
+
+This code implements a very simple (meta-)modelling tool.
+Its use is documented with the provided *help* function.
+A simple example of its use is shown below.
+
+.. image:: img/prompt_pn_interface.png
+
+In this case, note that the value of tokens is the string 3 instead of the integer (or natural) 3.
+Therefore, the conformance check will flag this value as incorrectly typed.

+ 376 - 0
doc/_build/html/examples.html

@@ -117,6 +117,382 @@ This is normal, though in the future the Modelverse will keep running for other
 </div>
 <div class="section" id="modelling-server">
 <h2>Modelling Server<a class="headerlink" href="#modelling-server" title="Permalink to this headline">¶</a></h2>
+<p>The simple Fibonacci server is not very relevant to the primary concern of the Modelverse: (meta-)modelling.
+But since we can create whatever kind of server we want, a simple (meta-)modelling server is created.
+The code offers an interface for users to execute modelling operations.
+The interface itself mostly just relays the incoming messages and operations to the internal modelling library.</p>
+<p>The full code is seen below:</p>
+<div class="highlight-default"><div class="highlight"><pre>include &quot;primitives.alh&quot;
+include &quot;constructors.alh&quot;
+include &quot;object_operations.alh&quot;
+include &quot;library.alh&quot;
+include &quot;conformance_scd.alh&quot;
+include &quot;io.alh&quot;
+include &quot;metamodels.alh&quot;
+include &quot;modelling.alh&quot;
+include &quot;compilation_manager.alh&quot;
+
+Element function model_loaded(model : Element):
+    String cmd
+
+    Element attr_list_pn
+    Element attr_keys_pn
+    String attr_key_pn
+    Element metamodel_element_pn
+    String typename
+    Boolean bottom
+    Element other_metamodel
+
+    bottom = False
+    other_metamodel = create_node()
+    dict_add(other_metamodel, &quot;model&quot;, model[&quot;model&quot;])
+    dict_add(other_metamodel, &quot;type_mapping&quot;, create_node())
+    dict_add(other_metamodel, &quot;metamodel&quot;, import_node(&quot;models/LTM_bottom&quot;))
+    dict_add(other_metamodel, &quot;inheritance&quot;, other_metamodel[&quot;metamodel&quot;][&quot;model&quot;][&quot;__Inheritance&quot;])
+
+    output(&quot;Model loaded, ready for commands!&quot;)
+    output(&quot;Use &#39;help&#39; command for a list of possible commands&quot;)
+
+    while (True):
+        output(&quot;Please give your command.&quot;)
+        cmd = input()
+        if (cmd == &quot;help&quot;):
+            output(&quot;Generic model operations:&quot;)
+            output(&quot;  instantiate -- Create a new model element&quot;)
+            output(&quot;  delete      -- Delete an existing element&quot;)
+            output(&quot;  attr_add    -- Add an attribute to an element&quot;)
+            output(&quot;  attr_del    -- Delete an attribute of an element&quot;)
+            output(&quot;  constrain   -- Add a constraint function to the model&quot;)
+            output(&quot;  rename      -- Rename an existing element&quot;)
+            output(&quot;  modify      -- Modify the attributes of an element&quot;)
+            output(&quot;  list        -- Prints the list of elements in the model&quot;)
+            output(&quot;  types       -- Prints the list of elements that can be instantiated&quot;)
+            output(&quot;  read        -- Prints the current state of a model element&quot;)
+            output(&quot;  verify      -- Check whether the model conforms to the metamodel&quot;)
+            output(&quot;  retype      -- Change the type of an element&quot;)
+            output(&quot;  switch      -- Switch between conformance bottom and the linguistic metamodel&quot;)
+            output(&quot;  exit        -- Unload the model and go back to the loading prompt&quot;)
+        elif (cmd == &quot;exit&quot;):
+            return model!
+        elif (cmd == &quot;instantiate&quot;):
+            String mm_type_name
+            output(&quot;Type to instantiate?&quot;)
+            mm_type_name = input()
+            if (dict_in(model[&quot;metamodel&quot;][&quot;model&quot;], mm_type_name)):
+                String element_name
+                output(&quot;Name of new element?&quot;)
+                element_name = input()
+                if (dict_in(model[&quot;model&quot;], element_name)):
+                    output(&quot;Element already exists; aborting&quot;)
+                else:
+                    if (is_edge(model[&quot;metamodel&quot;][&quot;model&quot;][mm_type_name])):
+                        output(&quot;Source name?&quot;)
+                        String src_name
+                        src_name = input()
+                        if (dict_in(model[&quot;model&quot;], src_name)):
+                            output(&quot;Destination name?&quot;)
+                            String dst_name
+                            dst_name = input()
+                            if (dict_in(model[&quot;model&quot;], dst_name)):
+                                instantiate_link(model, mm_type_name, element_name, src_name, dst_name)
+                                output(&quot;Instantiation successful!&quot;)
+                            else:
+                                output(&quot;Unknown destination; aborting&quot;)
+                        else:
+                            output(&quot;Unknown source; aborting&quot;)
+                    else:
+                        instantiate_node(model, mm_type_name, element_name)
+                        output(&quot;Instantiation successful!&quot;)
+            else:
+                output(&quot;Unknown type specified; aborting&quot;)
+        elif (cmd == &quot;set_inheritance&quot;):
+            String inh_name
+
+            output(&quot;Which link in the metamodel is the inheritance link?&quot;)
+            inh_name = input()
+
+            if (dict_in(model[&quot;metamodel&quot;][&quot;model&quot;], inh_name)):
+                dict_add(model, &quot;inheritance&quot;, model[&quot;metamodel&quot;][&quot;model&quot;][inh_name])
+                output(&quot;Set inheritance link!&quot;)
+            else:
+                output(&quot;Element not found in metamodel; aborting&quot;)
+
+        elif (cmd == &quot;constrain&quot;):
+            output(&quot;Element to constrain (empty for global)?&quot;)
+            String model_name
+            model_name = input()
+
+            if (model_name == &quot;&quot;):
+                // Global constraint
+                output(&quot;Give input to function constructors for GLOBAL constraint!&quot;)
+                set_model_constraints(model, construct_function())
+            elif (dict_in(model[&quot;model&quot;], model_name)):
+                // Local constraint for this model
+                output(&quot;Give input to function constructors for LOCAL constraint!&quot;)
+                add_constraint(model, model_name, construct_function())
+                output(&quot;Added constraint to model!&quot;)
+            else:
+                // Local constraint, but model not found
+                output(&quot;Unknown model; aborting&quot;)
+        elif (cmd == &quot;modify&quot;):
+            String model_name
+            output(&quot;Element to modify?&quot;)
+            model_name = input()
+            if (dict_in(model[&quot;model&quot;], model_name)):
+                Element attrs
+                attrs = getAttributeList(model, model_name)
+                String attr_name
+                output(&quot;Attribute to modify?&quot;)
+                attr_name = input()
+                if (set_in(dict_keys(attrs), attr_name)):
+                    output(&quot;New value?&quot;)
+                    unset_attribute(model, model_name, attr_name)
+                    instantiate_attribute(model, model_name, attr_name, input())
+                    output(&quot;Modified!&quot;)
+                else:
+                    output(&quot;No such attribute!&quot;)
+            else:
+                output(&quot;No such model!&quot;)
+        elif (cmd == &quot;attr_add&quot;):
+            String model_name
+            output(&quot;Which model do you want to assign an attribute to?&quot;)
+            model_name = input()
+            if (dict_in(model[&quot;model&quot;], model_name)):
+                Element attrs
+                attrs = getAttributeList(model, model_name)
+                String attr_name
+                output(&quot;Which attribute do you wish to assign?&quot;)
+                attr_name = input()
+                if (set_in(dict_keys(attrs), attr_name)):
+                    output(&quot;Value of attribute?&quot;)
+                    instantiate_attribute(model, model_name, attr_name, input())
+                    output(&quot;Added attribute!&quot;)
+                else:
+                    output(&quot;No such attribute!&quot;)
+            else:
+                output(&quot;No such model!&quot;)
+        elif (cmd == &quot;attr_del&quot;):
+            String model_name
+            output(&quot;Which model do you want to remove an attribute of?&quot;)
+            model_name = input()
+            if (dict_in(model[&quot;model&quot;], model_name)):
+                Element attrs
+                attrs = getAttributeList(model, model_name)
+                String attr_name
+                output(&quot;Which attribute do you want to delete?&quot;)
+                attr_name = input()
+                if (set_in(dict_keys(attrs), attr_name)):
+                    unset_attribute(model, model_name, attr_name)
+                    output(&quot;Attribute deleted!&quot;)
+                else:
+                    output(&quot;No such attribute!&quot;)
+            else:
+                output(&quot;No such model!&quot;)
+        elif (cmd == &quot;delete&quot;):
+            output(&quot;What is the name of the element you want to delete?&quot;)
+            cmd = input()
+            if (dict_in(model[&quot;model&quot;], cmd)):
+                model_delete_element(model, cmd)
+                output(&quot;Deleted!&quot;)
+            else:
+                output(&quot;No such element; aborting&quot;)
+        elif (cmd == &quot;rename&quot;):
+            output(&quot;Old name?&quot;)
+            String old_name_e
+            old_name_e = input()
+            if (dict_in(model[&quot;model&quot;], old_name_e)):
+                output(&quot;New name?&quot;)
+                String new_name_e
+                new_name_e = input()
+                if (dict_in(model[&quot;model&quot;], new_name_e)):
+                    output(&quot;New name already used; aborting&quot;)
+                else:
+                    dict_add(model[&quot;model&quot;], new_name_e, model[&quot;model&quot;][old_name_e])
+                    dict_delete(model[&quot;model&quot;], old_name_e)
+                    output(&quot;Rename complete!&quot;)
+            else:
+                output(&quot;Unknown element; aborting&quot;)
+        elif (cmd == &quot;list&quot;):
+            Element keys_m
+            keys_m = dict_keys(model[&quot;model&quot;])
+            output(&quot;List of all elements:&quot;)
+            String v_m
+            while (read_nr_out(keys_m) &gt; 0):
+                v_m = set_pop(keys_m)
+                // Filter out anonymous objects
+                if (bool_not(string_startswith(v_m, &quot;__&quot;))):
+                    typename = reverseKeyLookup(model[&quot;metamodel&quot;][&quot;model&quot;], dict_read_node(model[&quot;type_mapping&quot;], model[&quot;model&quot;][v_m]))
+                    output(((&quot;  &quot; + v_m) + &quot; : &quot;) + typename)
+        elif (cmd == &quot;read&quot;):
+            output(&quot;Element to read?&quot;)
+            cmd = input()
+            if (dict_in(model[&quot;model&quot;], cmd)):
+                Element read_elem
+                read_elem = model[&quot;model&quot;][cmd]
+                metamodel_element_pn = dict_read_node(model[&quot;type_mapping&quot;], read_elem)
+
+                output(&quot;Name: &quot; + cmd)
+                output(&quot;Type: &quot; + reverseKeyLookup(model[&quot;metamodel&quot;][&quot;model&quot;], metamodel_element_pn))
+                if (is_edge(read_elem)):
+                    output(&quot;Source: &quot; + reverseKeyLookup(model[&quot;model&quot;], read_edge_src(read_elem)))
+                    output(&quot;Destination: &quot; + reverseKeyLookup(model[&quot;model&quot;], read_edge_dst(read_elem)))
+                if (cast_v2s(read_elem) != &quot;None&quot;):
+                    output(&quot;Value: &quot; + cast_v2s(read_elem))
+                output(&quot;Defines attributes:&quot;)
+                attr_list_pn = getInstantiatableAttributes(model, read_elem)
+                attr_keys_pn = dict_keys(attr_list_pn)
+                while (0 &lt; read_nr_out(attr_keys_pn)):
+                    attr_key_pn = set_pop(attr_keys_pn)
+                    output((((&quot;  &quot; + attr_key_pn) + &quot; : &quot;) + cast_v2s(attr_list_pn[attr_key_pn])))
+                output(&quot;Attributes:&quot;)
+                attr_list_pn = getAttributeList(model, cmd)
+                attr_keys_pn = dict_keys(attr_list_pn)
+                while (0 &lt; read_nr_out(attr_keys_pn)):
+                    attr_key_pn = set_pop(attr_keys_pn)
+                    output(((((&quot;  &quot; + cast_v2s(attr_key_pn)) + &quot; : &quot;) + cast_v2s(attr_list_pn[attr_key_pn])) + &quot; = &quot;) + cast_v2s(read_attribute(model, reverseKeyLookup(model[&quot;model&quot;], read_elem), attr_key_pn)))
+            else:
+                output(&quot;Unknown element; aborting&quot;)
+        elif (cmd == &quot;verify&quot;):
+            output(conformance_scd(model))
+        elif (cmd == &quot;types&quot;):
+            Element keys_t
+            keys_t = dict_keys(model[&quot;metamodel&quot;][&quot;model&quot;])
+            output(&quot;List of types:&quot;)
+            String v_t
+            while (read_nr_out(keys_t) &gt; 0):
+                v_t = set_pop(keys_t)
+                if (bool_not(string_startswith(v_t, &quot;__&quot;))):
+                    output(string_join((&quot;  &quot; + v_t) + &quot; : &quot;, reverseKeyLookup(model[&quot;metamodel&quot;][&quot;metamodel&quot;][&quot;model&quot;], dict_read_node(model[&quot;metamodel&quot;][&quot;type_mapping&quot;], model[&quot;metamodel&quot;][&quot;model&quot;][v_t]))))
+        elif (cmd == &quot;retype&quot;):
+            output(&quot;Element to retype?&quot;)
+            String elementname
+            elementname = input()
+            if (dict_in(model[&quot;model&quot;], elementname)):
+                output(&quot;New type&quot;)
+                typename = input()
+                if (dict_in(model[&quot;metamodel&quot;][&quot;model&quot;], typename)):
+                    // OK, do the retyping
+                    // First try removing the previous type if it exists
+                    dict_delete(model[&quot;type_mapping&quot;], model[&quot;model&quot;][elementname])
+                    // Now add the new type
+                    dict_add(model[&quot;type_mapping&quot;], model[&quot;model&quot;][elementname], model[&quot;metamodel&quot;][&quot;model&quot;][typename])
+                    output(&quot;Retyped!&quot;)
+                else:
+                    output(&quot;Unknown type; aborting&quot;)
+            else:
+                output(&quot;Unknown element; aborting&quot;)
+        elif (cmd == &quot;switch&quot;):
+            bottom = bool_not(bottom)
+
+            Element tmp_model
+            tmp_model = model
+            model = other_metamodel
+            other_metamodel = tmp_model
+
+            if (bottom):
+                // The type mapping we are using is probably not complete for our model
+                // so we completely recreate it from the model we have.
+                output(&quot;Switching to conformance bottom mode!&quot;)
+                generate_bottom_type_mapping(model)
+            else:
+                // We already switched the models and such, so we are already done!
+                output(&quot;Switching to linguistic metamodel!&quot;)
+        else:
+            output(&quot;Unknown command: &quot; + cast_v2s(cmd))
+            output(&quot;Use command &#39;help&#39; to get a list of available commands&quot;)
+
+Element function main():
+    output(&quot;Welcome to the Model Management Interface, running live on the Modelverse!&quot;)
+    output(&quot;Use &#39;help&#39; command for a list of possible commands&quot;)
+    String command
+    Element root
+    Element metamodel
+    String name
+    Element my_model
+    String mm_name
+
+    root = create_metamodels()
+
+    while (True):
+        output(&quot;Please give your command.&quot;)
+        command = input()
+
+        if (command == &quot;help&quot;):
+            output(&quot;Currently no model is loaded, so your operations are limited to:&quot;)
+            output(&quot;  new    -- Create a new model and save it for future use&quot;)
+            output(&quot;  load   -- Load a previously made model&quot;)
+            output(&quot;  rename -- Rename a previously made model&quot;)
+            output(&quot;  delete -- Delete a previously made model&quot;)
+            output(&quot;  list   -- Show a list of all stored models&quot;)
+            output(&quot;  help   -- Show a list of possible commands&quot;)
+        elif (command == &quot;new&quot;):
+            output(&quot;Metamodel to instantiate?&quot;)
+            mm_name = input()
+            if (dict_in(root, mm_name)):
+                output(&quot;Name of model?&quot;)
+                name = input()
+                if (dict_in(root, name)):
+                    output(&quot;Model exists; aborting&quot;)
+                else:
+                    my_model = instantiate_model(root[mm_name])
+                    dict_add(root, name, my_model)
+                    model_loaded(my_model)
+            else:
+                output(&quot;Unknown metamodel; aborting&quot;)
+        elif (command == &quot;load&quot;):
+            output(&quot;Model to load?&quot;)
+            name = input()
+            if (dict_in(root, name)):
+                my_model = root[name]
+                model_loaded(my_model)
+            else:
+                output(&quot;Model not found; aborting&quot;)
+        elif (command == &quot;list&quot;):
+            Element keys
+            String m_menu_list
+            keys = dict_keys(root)
+            output(&quot;Found models:&quot;)
+            while (read_nr_out(keys) &gt; 0):
+                m_menu_list = set_pop(keys)
+                output(((&quot;  &quot; + m_menu_list) + &quot; : &quot;) + reverseKeyLookup(root, root[m_menu_list][&quot;metamodel&quot;]))
+        elif (command == &quot;delete&quot;):
+            output(&quot;Model to delete?&quot;)
+            name = input()
+            if (dict_in(root, name)):
+                dict_delete(root, name)
+                output(&quot;Deleted!&quot;)
+            else:
+                output(&quot;Model not found; aborting&quot;)
+        elif (command == &quot;rename&quot;):
+            output(&quot;Old name?&quot;)
+            String old_name
+            old_name = input()
+            if (dict_in(root, old_name)):
+                output(&quot;New name?&quot;)
+                String new_name
+                new_name = input()
+                if (dict_in(root, new_name)):
+                    output(&quot;Model exists; aborting&quot;)
+                else:
+                    dict_add(root, new_name, root[old_name])
+                    dict_delete(root, old_name)
+                    output(&quot;Rename complete!&quot;)
+            else:
+                output(&quot;Model not found; aborting&quot;)
+        elif (command == &quot;actions&quot;):
+            output(&quot;Switching to compilation manager!&quot;)
+            compilation_manager()
+            output(&quot;Back in model manager!&quot;)
+        else:
+            output(&quot;Command not recognized, use &#39;help&#39; for a list of possible commands&quot;)
+</pre></div>
+</div>
+<p>This code implements a very simple (meta-)modelling tool.
+Its use is documented with the provided <em>help</em> function.
+A simple example of its use is shown below.</p>
+<img alt="_images/prompt_pn_interface.png" src="_images/prompt_pn_interface.png" />
+<p>In this case, note that the value of tokens is the string 3 instead of the integer (or natural) 3.
+Therefore, the conformance check will flag this value as incorrectly typed.</p>
 </div>
 </div>
 

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 1 - 1
doc/_build/html/searchindex.js


+ 380 - 0
doc/examples.rst

@@ -75,3 +75,383 @@ This is normal, though in the future the Modelverse will keep running for other
 
 Modelling Server
 ----------------
+
+The simple Fibonacci server is not very relevant to the primary concern of the Modelverse: (meta-)modelling.
+But since we can create whatever kind of server we want, a simple (meta-)modelling server is created.
+The code offers an interface for users to execute modelling operations.
+The interface itself mostly just relays the incoming messages and operations to the internal modelling library.
+
+The full code is seen below::
+
+    include "primitives.alh"
+    include "constructors.alh"
+    include "object_operations.alh"
+    include "library.alh"
+    include "conformance_scd.alh"
+    include "io.alh"
+    include "metamodels.alh"
+    include "modelling.alh"
+    include "compilation_manager.alh"
+
+    Element function model_loaded(model : Element):
+        String cmd
+
+        Element attr_list_pn
+        Element attr_keys_pn
+        String attr_key_pn
+        Element metamodel_element_pn
+        String typename
+        Boolean bottom
+        Element other_metamodel
+
+        bottom = False
+        other_metamodel = create_node()
+        dict_add(other_metamodel, "model", model["model"])
+        dict_add(other_metamodel, "type_mapping", create_node())
+        dict_add(other_metamodel, "metamodel", import_node("models/LTM_bottom"))
+        dict_add(other_metamodel, "inheritance", other_metamodel["metamodel"]["model"]["__Inheritance"])
+
+        output("Model loaded, ready for commands!")
+        output("Use 'help' command for a list of possible commands")
+
+        while (True):
+            output("Please give your command.")
+            cmd = input()
+            if (cmd == "help"):
+                output("Generic model operations:")
+                output("  instantiate -- Create a new model element")
+                output("  delete      -- Delete an existing element")
+                output("  attr_add    -- Add an attribute to an element")
+                output("  attr_del    -- Delete an attribute of an element")
+                output("  constrain   -- Add a constraint function to the model")
+                output("  rename      -- Rename an existing element")
+                output("  modify      -- Modify the attributes of an element")
+                output("  list        -- Prints the list of elements in the model")
+                output("  types       -- Prints the list of elements that can be instantiated")
+                output("  read        -- Prints the current state of a model element")
+                output("  verify      -- Check whether the model conforms to the metamodel")
+                output("  retype      -- Change the type of an element")
+                output("  switch      -- Switch between conformance bottom and the linguistic metamodel")
+                output("  exit        -- Unload the model and go back to the loading prompt")
+            elif (cmd == "exit"):
+                return model!
+            elif (cmd == "instantiate"):
+                String mm_type_name
+                output("Type to instantiate?")
+                mm_type_name = input()
+                if (dict_in(model["metamodel"]["model"], mm_type_name)):
+                    String element_name
+                    output("Name of new element?")
+                    element_name = input()
+                    if (dict_in(model["model"], element_name)):
+                        output("Element already exists; aborting")
+                    else:
+                        if (is_edge(model["metamodel"]["model"][mm_type_name])):
+                            output("Source name?")
+                            String src_name
+                            src_name = input()
+                            if (dict_in(model["model"], src_name)):
+                                output("Destination name?")
+                                String dst_name
+                                dst_name = input()
+                                if (dict_in(model["model"], dst_name)):
+                                    instantiate_link(model, mm_type_name, element_name, src_name, dst_name)
+                                    output("Instantiation successful!")
+                                else:
+                                    output("Unknown destination; aborting")
+                            else:
+                                output("Unknown source; aborting")
+                        else:
+                            instantiate_node(model, mm_type_name, element_name)
+                            output("Instantiation successful!")
+                else:
+                    output("Unknown type specified; aborting")
+            elif (cmd == "set_inheritance"):
+                String inh_name
+
+                output("Which link in the metamodel is the inheritance link?")
+                inh_name = input()
+
+                if (dict_in(model["metamodel"]["model"], inh_name)):
+                    dict_add(model, "inheritance", model["metamodel"]["model"][inh_name])
+                    output("Set inheritance link!")
+                else:
+                    output("Element not found in metamodel; aborting")
+
+            elif (cmd == "constrain"):
+                output("Element to constrain (empty for global)?")
+                String model_name
+                model_name = input()
+
+                if (model_name == ""):
+                    // Global constraint
+                    output("Give input to function constructors for GLOBAL constraint!")
+                    set_model_constraints(model, construct_function())
+                elif (dict_in(model["model"], model_name)):
+                    // Local constraint for this model
+                    output("Give input to function constructors for LOCAL constraint!")
+                    add_constraint(model, model_name, construct_function())
+                    output("Added constraint to model!")
+                else:
+                    // Local constraint, but model not found
+                    output("Unknown model; aborting")
+            elif (cmd == "modify"):
+                String model_name
+                output("Element to modify?")
+                model_name = input()
+                if (dict_in(model["model"], model_name)):
+                    Element attrs
+                    attrs = getAttributeList(model, model_name)
+                    String attr_name
+                    output("Attribute to modify?")
+                    attr_name = input()
+                    if (set_in(dict_keys(attrs), attr_name)):
+                        output("New value?")
+                        unset_attribute(model, model_name, attr_name)
+                        instantiate_attribute(model, model_name, attr_name, input())
+                        output("Modified!")
+                    else:
+                        output("No such attribute!")
+                else:
+                    output("No such model!")
+            elif (cmd == "attr_add"):
+                String model_name
+                output("Which model do you want to assign an attribute to?")
+                model_name = input()
+                if (dict_in(model["model"], model_name)):
+                    Element attrs
+                    attrs = getAttributeList(model, model_name)
+                    String attr_name
+                    output("Which attribute do you wish to assign?")
+                    attr_name = input()
+                    if (set_in(dict_keys(attrs), attr_name)):
+                        output("Value of attribute?")
+                        instantiate_attribute(model, model_name, attr_name, input())
+                        output("Added attribute!")
+                    else:
+                        output("No such attribute!")
+                else:
+                    output("No such model!")
+            elif (cmd == "attr_del"):
+                String model_name
+                output("Which model do you want to remove an attribute of?")
+                model_name = input()
+                if (dict_in(model["model"], model_name)):
+                    Element attrs
+                    attrs = getAttributeList(model, model_name)
+                    String attr_name
+                    output("Which attribute do you want to delete?")
+                    attr_name = input()
+                    if (set_in(dict_keys(attrs), attr_name)):
+                        unset_attribute(model, model_name, attr_name)
+                        output("Attribute deleted!")
+                    else:
+                        output("No such attribute!")
+                else:
+                    output("No such model!")
+            elif (cmd == "delete"):
+                output("What is the name of the element you want to delete?")
+                cmd = input()
+                if (dict_in(model["model"], cmd)):
+                    model_delete_element(model, cmd)
+                    output("Deleted!")
+                else:
+                    output("No such element; aborting")
+            elif (cmd == "rename"):
+                output("Old name?")
+                String old_name_e
+                old_name_e = input()
+                if (dict_in(model["model"], old_name_e)):
+                    output("New name?")
+                    String new_name_e
+                    new_name_e = input()
+                    if (dict_in(model["model"], new_name_e)):
+                        output("New name already used; aborting")
+                    else:
+                        dict_add(model["model"], new_name_e, model["model"][old_name_e])
+                        dict_delete(model["model"], old_name_e)
+                        output("Rename complete!")
+                else:
+                    output("Unknown element; aborting")
+            elif (cmd == "list"):
+                Element keys_m
+                keys_m = dict_keys(model["model"])
+                output("List of all elements:")
+                String v_m
+                while (read_nr_out(keys_m) > 0):
+                    v_m = set_pop(keys_m)
+                    // Filter out anonymous objects
+                    if (bool_not(string_startswith(v_m, "__"))):
+                        typename = reverseKeyLookup(model["metamodel"]["model"], dict_read_node(model["type_mapping"], model["model"][v_m]))
+                        output((("  " + v_m) + " : ") + typename)
+            elif (cmd == "read"):
+                output("Element to read?")
+                cmd = input()
+                if (dict_in(model["model"], cmd)):
+                    Element read_elem
+                    read_elem = model["model"][cmd]
+                    metamodel_element_pn = dict_read_node(model["type_mapping"], read_elem)
+
+                    output("Name: " + cmd)
+                    output("Type: " + reverseKeyLookup(model["metamodel"]["model"], metamodel_element_pn))
+                    if (is_edge(read_elem)):
+                        output("Source: " + reverseKeyLookup(model["model"], read_edge_src(read_elem)))
+                        output("Destination: " + reverseKeyLookup(model["model"], read_edge_dst(read_elem)))
+                    if (cast_v2s(read_elem) != "None"):
+                        output("Value: " + cast_v2s(read_elem))
+                    output("Defines attributes:")
+                    attr_list_pn = getInstantiatableAttributes(model, read_elem)
+                    attr_keys_pn = dict_keys(attr_list_pn)
+                    while (0 < read_nr_out(attr_keys_pn)):
+                        attr_key_pn = set_pop(attr_keys_pn)
+                        output(((("  " + attr_key_pn) + " : ") + cast_v2s(attr_list_pn[attr_key_pn])))
+                    output("Attributes:")
+                    attr_list_pn = getAttributeList(model, cmd)
+                    attr_keys_pn = dict_keys(attr_list_pn)
+                    while (0 < read_nr_out(attr_keys_pn)):
+                        attr_key_pn = set_pop(attr_keys_pn)
+                        output((((("  " + cast_v2s(attr_key_pn)) + " : ") + cast_v2s(attr_list_pn[attr_key_pn])) + " = ") + cast_v2s(read_attribute(model, reverseKeyLookup(model["model"], read_elem), attr_key_pn)))
+                else:
+                    output("Unknown element; aborting")
+            elif (cmd == "verify"):
+                output(conformance_scd(model))
+            elif (cmd == "types"):
+                Element keys_t
+                keys_t = dict_keys(model["metamodel"]["model"])
+                output("List of types:")
+                String v_t
+                while (read_nr_out(keys_t) > 0):
+                    v_t = set_pop(keys_t)
+                    if (bool_not(string_startswith(v_t, "__"))):
+                        output(string_join(("  " + v_t) + " : ", reverseKeyLookup(model["metamodel"]["metamodel"]["model"], dict_read_node(model["metamodel"]["type_mapping"], model["metamodel"]["model"][v_t]))))
+            elif (cmd == "retype"):
+                output("Element to retype?")
+                String elementname
+                elementname = input()
+                if (dict_in(model["model"], elementname)):
+                    output("New type")
+                    typename = input()
+                    if (dict_in(model["metamodel"]["model"], typename)):
+                        // OK, do the retyping
+                        // First try removing the previous type if it exists
+                        dict_delete(model["type_mapping"], model["model"][elementname])
+                        // Now add the new type
+                        dict_add(model["type_mapping"], model["model"][elementname], model["metamodel"]["model"][typename])
+                        output("Retyped!")
+                    else:
+                        output("Unknown type; aborting")
+                else:
+                    output("Unknown element; aborting")
+            elif (cmd == "switch"):
+                bottom = bool_not(bottom)
+
+                Element tmp_model
+                tmp_model = model
+                model = other_metamodel
+                other_metamodel = tmp_model
+
+                if (bottom):
+                    // The type mapping we are using is probably not complete for our model
+                    // so we completely recreate it from the model we have.
+                    output("Switching to conformance bottom mode!")
+                    generate_bottom_type_mapping(model)
+                else:
+                    // We already switched the models and such, so we are already done!
+                    output("Switching to linguistic metamodel!")
+            else:
+                output("Unknown command: " + cast_v2s(cmd))
+                output("Use command 'help' to get a list of available commands")
+
+    Element function main():
+        output("Welcome to the Model Management Interface, running live on the Modelverse!")
+        output("Use 'help' command for a list of possible commands")
+        String command
+        Element root
+        Element metamodel
+        String name
+        Element my_model
+        String mm_name
+
+        root = create_metamodels()
+
+        while (True):
+            output("Please give your command.")
+            command = input()
+
+            if (command == "help"):
+                output("Currently no model is loaded, so your operations are limited to:")
+                output("  new    -- Create a new model and save it for future use")
+                output("  load   -- Load a previously made model")
+                output("  rename -- Rename a previously made model")
+                output("  delete -- Delete a previously made model")
+                output("  list   -- Show a list of all stored models")
+                output("  help   -- Show a list of possible commands")
+            elif (command == "new"):
+                output("Metamodel to instantiate?")
+                mm_name = input()
+                if (dict_in(root, mm_name)):
+                    output("Name of model?")
+                    name = input()
+                    if (dict_in(root, name)):
+                        output("Model exists; aborting")
+                    else:
+                        my_model = instantiate_model(root[mm_name])
+                        dict_add(root, name, my_model)
+                        model_loaded(my_model)
+                else:
+                    output("Unknown metamodel; aborting")
+            elif (command == "load"):
+                output("Model to load?")
+                name = input()
+                if (dict_in(root, name)):
+                    my_model = root[name]
+                    model_loaded(my_model)
+                else:
+                    output("Model not found; aborting")
+            elif (command == "list"):
+                Element keys
+                String m_menu_list
+                keys = dict_keys(root)
+                output("Found models:")
+                while (read_nr_out(keys) > 0):
+                    m_menu_list = set_pop(keys)
+                    output((("  " + m_menu_list) + " : ") + reverseKeyLookup(root, root[m_menu_list]["metamodel"]))
+            elif (command == "delete"):
+                output("Model to delete?")
+                name = input()
+                if (dict_in(root, name)):
+                    dict_delete(root, name)
+                    output("Deleted!")
+                else:
+                    output("Model not found; aborting")
+            elif (command == "rename"):
+                output("Old name?")
+                String old_name
+                old_name = input()
+                if (dict_in(root, old_name)):
+                    output("New name?")
+                    String new_name
+                    new_name = input()
+                    if (dict_in(root, new_name)):
+                        output("Model exists; aborting")
+                    else:
+                        dict_add(root, new_name, root[old_name])
+                        dict_delete(root, old_name)
+                        output("Rename complete!")
+                else:
+                    output("Model not found; aborting")
+            elif (command == "actions"):
+                output("Switching to compilation manager!")
+                compilation_manager()
+                output("Back in model manager!")
+            else:
+                output("Command not recognized, use 'help' for a list of possible commands")
+
+This code implements a very simple (meta-)modelling tool.
+Its use is documented with the provided *help* function.
+A simple example of its use is shown below.
+
+.. image:: img/prompt_pn_interface.png
+
+In this case, note that the value of tokens is the string 3 instead of the integer (or natural) 3.
+Therefore, the conformance check will flag this value as incorrectly typed.

BIN
doc/img/prompt_pn_interface.png