examples.html 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>Examples &#8212; Modelverse 0.4.0 documentation</title>
  7. <link rel="stylesheet" href="_static/classic.css" type="text/css" />
  8. <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  9. <script type="text/javascript">
  10. var DOCUMENTATION_OPTIONS = {
  11. URL_ROOT: './',
  12. VERSION: '0.4.0',
  13. COLLAPSE_INDEX: false,
  14. FILE_SUFFIX: '.html',
  15. HAS_SOURCE: true
  16. };
  17. </script>
  18. <script type="text/javascript" src="_static/jquery.js"></script>
  19. <script type="text/javascript" src="_static/underscore.js"></script>
  20. <script type="text/javascript" src="_static/doctools.js"></script>
  21. <link rel="top" title="Modelverse 0.4.0 documentation" href="index.html" />
  22. <link rel="next" title="Advanced examples" href="advanced.html" />
  23. <link rel="prev" title="Modelling Language" href="modellanguage.html" />
  24. </head>
  25. <body role="document">
  26. <div class="related" role="navigation" aria-label="related navigation">
  27. <h3>Navigation</h3>
  28. <ul>
  29. <li class="right" style="margin-right: 10px">
  30. <a href="genindex.html" title="General Index"
  31. accesskey="I">index</a></li>
  32. <li class="right" >
  33. <a href="advanced.html" title="Advanced examples"
  34. accesskey="N">next</a> |</li>
  35. <li class="right" >
  36. <a href="modellanguage.html" title="Modelling Language"
  37. accesskey="P">previous</a> |</li>
  38. <li class="nav-item nav-item-0"><a href="index.html">Modelverse 0.4.0 documentation</a> &#187;</li>
  39. </ul>
  40. </div>
  41. <div class="document">
  42. <div class="documentwrapper">
  43. <div class="bodywrapper">
  44. <div class="body" role="main">
  45. <div class="section" id="examples">
  46. <h1>Examples<a class="headerlink" href="#examples" title="Permalink to this headline">¶</a></h1>
  47. <p>To run this code, store it in a file (<em>e.g.</em>, test.alc), and execute the following commands:</p>
  48. <div class="highlight-default"><div class="highlight"><pre><span class="n">python</span> <span class="n">scripts</span><span class="o">/</span><span class="n">run_local_modelverse</span><span class="o">.</span><span class="n">py</span> <span class="mi">8001</span> <span class="o">&amp;</span>
  49. <span class="n">python</span> <span class="n">scripts</span><span class="o">/</span><span class="n">make_parallel</span><span class="o">.</span><span class="n">py</span> <span class="n">http</span><span class="p">:</span><span class="o">//</span><span class="n">localhost</span><span class="p">:</span><span class="mi">8001</span> <span class="n">test</span> <span class="n">test</span><span class="o">.</span><span class="n">alc</span> <span class="n">bootstrap</span><span class="o">/</span><span class="n">primitives</span><span class="o">.</span><span class="n">alc</span>
  50. <span class="n">python</span> <span class="n">scripts</span><span class="o">/</span><span class="n">prompt</span><span class="o">.</span><span class="n">py</span>
  51. </pre></div>
  52. </div>
  53. <p>In the prompt, log on to <a class="reference external" href="http://localhost:8001">http://localhost:8001</a> as user <em>test</em>.
  54. Now, all input you send, will be caught in the <em>input()</em> calls seen in the code.
  55. Results will also be printed.</p>
  56. <p>Note that all content will, by default, be typed as string.
  57. If you want to send integers or so, prepend the input with a backslash (\), which allows you to directly input the JSON code.
  58. For example, input <em>5</em> will be received as the string &#8220;5&#8221;.
  59. To send the integer 5, the input should be <em>\5</em>.</p>
  60. <div class="section" id="fibonacci-server">
  61. <h2>Fibonacci Server<a class="headerlink" href="#fibonacci-server" title="Permalink to this headline">¶</a></h2>
  62. <p>The first example is a simple Fibonacci server.
  63. The code is identical to the action language example from before, as this already included the <em>server</em> part (<em>i.e.</em>, the while loop).
  64. Now we will just connect to it using <em>prompt.py</em> and try out the code directly.</p>
  65. <p>The code is repeated below:</p>
  66. <div class="highlight-default"><div class="highlight"><pre>include &quot;primitives.alh&quot;
  67. Integer function fib(param : Integer):
  68. if (param &lt;= 2):
  69. return 1!
  70. else:
  71. return fib(param - 1) + fib(param - 2)!
  72. Void function main():
  73. while(True):
  74. output(fib(input()))
  75. </pre></div>
  76. </div>
  77. <p>To run this code, save it to a file (<em>e.g.</em>, fibonacci.alc) and execute the following command:</p>
  78. <div class="highlight-default"><div class="highlight"><pre><span class="n">python</span> <span class="n">scripts</span><span class="o">/</span><span class="n">run_local_modelverse</span><span class="o">.</span><span class="n">py</span> <span class="mi">8001</span>
  79. </pre></div>
  80. </div>
  81. <p>Now, the Modelverse is running, but we still need to upload our code.
  82. To compile the file, together with the primitives.alc file, execute the following command:</p>
  83. <div class="highlight-default"><div class="highlight"><pre><span class="n">python</span> <span class="n">scripts</span><span class="o">/</span><span class="n">make_parallel</span><span class="o">.</span><span class="n">py</span> <span class="n">http</span><span class="p">:</span><span class="o">//</span><span class="n">localhost</span><span class="p">:</span><span class="mi">8001</span> <span class="n">test</span> <span class="n">fibonacci</span><span class="o">.</span><span class="n">alc</span> <span class="n">bootstrap</span><span class="o">/</span><span class="n">primitives</span><span class="o">.</span><span class="n">alc</span>
  84. </pre></div>
  85. </div>
  86. <p>When this finishes, the Modelverse now stores a copy of our code in its own format.
  87. The Modelverse will automatically create the user <em>test</em> and start executing the <em>main</em> function as this user.
  88. We can therefore simply connect to the Modelverse as the <em>test</em> user and start seeing the responses.
  89. To start the prompt, execute the following command:</p>
  90. <div class="highlight-default"><div class="highlight"><pre><span class="n">python</span> <span class="n">scripts</span><span class="o">/</span><span class="n">prompt</span><span class="o">.</span><span class="n">py</span>
  91. </pre></div>
  92. </div>
  93. <p>In this prompt tool, you first have to configure the location of the Modelverse and the username.
  94. The defaults should be fine, so just press &lt;return&gt; twice.
  95. After that, you are in direct connection with the Modelverse.
  96. Each message you type in, is made available in the <em>input()</em> function of the code.
  97. Remember that, to send integers, you have to prefix this with a backslash (\).
  98. To get, for example, the 1st Fibonacci number, type in the command:</p>
  99. <div class="highlight-default"><div class="highlight"><pre>\<span class="mi">1</span>
  100. </pre></div>
  101. </div>
  102. <p>You will now see the following.</p>
  103. <img alt="_images/prompt_fibonacci.png" src="_images/prompt_fibonacci.png" />
  104. <p>Since we are in an unconditional loop, you can send as many requests as you want, as long as they are understandable by the <em>fib</em> function.</p>
  105. <img alt="_images/prompt_fibonacci_more.png" src="_images/prompt_fibonacci_more.png" />
  106. <p>Inputting a string directly, such as <em>1</em> instead of <em>\1</em>, will make the Modelverse crash on the execution of this code.
  107. This is normal, though in the future the Modelverse will keep running for other users: only the current user&#8217;s code will be interrupted.</p>
  108. </div>
  109. <div class="section" id="modelling-server">
  110. <h2>Modelling Server<a class="headerlink" href="#modelling-server" title="Permalink to this headline">¶</a></h2>
  111. <p>The simple Fibonacci server is not very relevant to the primary concern of the Modelverse: (meta-)modelling.
  112. But since we can create whatever kind of server we want, a simple (meta-)modelling server is created.
  113. The code offers an interface for users to execute modelling operations.
  114. The interface itself mostly just relays the incoming messages and operations to the internal modelling library.</p>
  115. <p>The full code is seen below:</p>
  116. <div class="highlight-default"><div class="highlight"><pre>include &quot;primitives.alh&quot;
  117. include &quot;constructors.alh&quot;
  118. include &quot;object_operations.alh&quot;
  119. include &quot;library.alh&quot;
  120. include &quot;conformance_scd.alh&quot;
  121. include &quot;io.alh&quot;
  122. include &quot;metamodels.alh&quot;
  123. include &quot;modelling.alh&quot;
  124. include &quot;compilation_manager.alh&quot;
  125. Element function model_loaded(model : Element):
  126. String cmd
  127. Element attr_list_pn
  128. Element attr_keys_pn
  129. String attr_key_pn
  130. Element metamodel_element_pn
  131. String typename
  132. Boolean bottom
  133. Element other_metamodel
  134. bottom = False
  135. other_metamodel = create_node()
  136. dict_add(other_metamodel, &quot;model&quot;, model[&quot;model&quot;])
  137. dict_add(other_metamodel, &quot;type_mapping&quot;, create_node())
  138. dict_add(other_metamodel, &quot;metamodel&quot;, import_node(&quot;models/LTM_bottom&quot;))
  139. dict_add(other_metamodel, &quot;inheritance&quot;, other_metamodel[&quot;metamodel&quot;][&quot;model&quot;][&quot;__Inheritance&quot;])
  140. output(&quot;Model loaded, ready for commands!&quot;)
  141. output(&quot;Use &#39;help&#39; command for a list of possible commands&quot;)
  142. while (True):
  143. output(&quot;Please give your command.&quot;)
  144. cmd = input()
  145. if (cmd == &quot;help&quot;):
  146. output(&quot;Generic model operations:&quot;)
  147. output(&quot; instantiate -- Create a new model element&quot;)
  148. output(&quot; delete -- Delete an existing element&quot;)
  149. output(&quot; attr_add -- Add an attribute to an element&quot;)
  150. output(&quot; attr_del -- Delete an attribute of an element&quot;)
  151. output(&quot; constrain -- Add a constraint function to the model&quot;)
  152. output(&quot; rename -- Rename an existing element&quot;)
  153. output(&quot; modify -- Modify the attributes of an element&quot;)
  154. output(&quot; list -- Prints the list of elements in the model&quot;)
  155. output(&quot; types -- Prints the list of elements that can be instantiated&quot;)
  156. output(&quot; read -- Prints the current state of a model element&quot;)
  157. output(&quot; verify -- Check whether the model conforms to the metamodel&quot;)
  158. output(&quot; retype -- Change the type of an element&quot;)
  159. output(&quot; switch -- Switch between conformance bottom and the linguistic metamodel&quot;)
  160. output(&quot; exit -- Unload the model and go back to the loading prompt&quot;)
  161. elif (cmd == &quot;exit&quot;):
  162. return model!
  163. elif (cmd == &quot;instantiate&quot;):
  164. String mm_type_name
  165. output(&quot;Type to instantiate?&quot;)
  166. mm_type_name = input()
  167. if (dict_in(model[&quot;metamodel&quot;][&quot;model&quot;], mm_type_name)):
  168. String element_name
  169. output(&quot;Name of new element?&quot;)
  170. element_name = input()
  171. if (dict_in(model[&quot;model&quot;], element_name)):
  172. output(&quot;Element already exists; aborting&quot;)
  173. else:
  174. if (is_edge(model[&quot;metamodel&quot;][&quot;model&quot;][mm_type_name])):
  175. output(&quot;Source name?&quot;)
  176. String src_name
  177. src_name = input()
  178. if (dict_in(model[&quot;model&quot;], src_name)):
  179. output(&quot;Destination name?&quot;)
  180. String dst_name
  181. dst_name = input()
  182. if (dict_in(model[&quot;model&quot;], dst_name)):
  183. instantiate_link(model, mm_type_name, element_name, src_name, dst_name)
  184. output(&quot;Instantiation successful!&quot;)
  185. else:
  186. output(&quot;Unknown destination; aborting&quot;)
  187. else:
  188. output(&quot;Unknown source; aborting&quot;)
  189. else:
  190. instantiate_node(model, mm_type_name, element_name)
  191. output(&quot;Instantiation successful!&quot;)
  192. else:
  193. output(&quot;Unknown type specified; aborting&quot;)
  194. elif (cmd == &quot;set_inheritance&quot;):
  195. String inh_name
  196. output(&quot;Which link in the metamodel is the inheritance link?&quot;)
  197. inh_name = input()
  198. if (dict_in(model[&quot;metamodel&quot;][&quot;model&quot;], inh_name)):
  199. dict_add(model, &quot;inheritance&quot;, model[&quot;metamodel&quot;][&quot;model&quot;][inh_name])
  200. output(&quot;Set inheritance link!&quot;)
  201. else:
  202. output(&quot;Element not found in metamodel; aborting&quot;)
  203. elif (cmd == &quot;constrain&quot;):
  204. output(&quot;Element to constrain (empty for global)?&quot;)
  205. String model_name
  206. model_name = input()
  207. if (model_name == &quot;&quot;):
  208. // Global constraint
  209. output(&quot;Give input to function constructors for GLOBAL constraint!&quot;)
  210. set_model_constraints(model, construct_function())
  211. elif (dict_in(model[&quot;model&quot;], model_name)):
  212. // Local constraint for this model
  213. output(&quot;Give input to function constructors for LOCAL constraint!&quot;)
  214. add_constraint(model, model_name, construct_function())
  215. output(&quot;Added constraint to model!&quot;)
  216. else:
  217. // Local constraint, but model not found
  218. output(&quot;Unknown model; aborting&quot;)
  219. elif (cmd == &quot;modify&quot;):
  220. String model_name
  221. output(&quot;Element to modify?&quot;)
  222. model_name = input()
  223. if (dict_in(model[&quot;model&quot;], model_name)):
  224. Element attrs
  225. attrs = getAttributeList(model, model_name)
  226. String attr_name
  227. output(&quot;Attribute to modify?&quot;)
  228. attr_name = input()
  229. if (set_in(dict_keys(attrs), attr_name)):
  230. output(&quot;New value?&quot;)
  231. unset_attribute(model, model_name, attr_name)
  232. instantiate_attribute(model, model_name, attr_name, input())
  233. output(&quot;Modified!&quot;)
  234. else:
  235. output(&quot;No such attribute!&quot;)
  236. else:
  237. output(&quot;No such model!&quot;)
  238. elif (cmd == &quot;attr_add&quot;):
  239. String model_name
  240. output(&quot;Which model do you want to assign an attribute to?&quot;)
  241. model_name = input()
  242. if (dict_in(model[&quot;model&quot;], model_name)):
  243. Element attrs
  244. attrs = getAttributeList(model, model_name)
  245. String attr_name
  246. output(&quot;Which attribute do you wish to assign?&quot;)
  247. attr_name = input()
  248. if (set_in(dict_keys(attrs), attr_name)):
  249. output(&quot;Value of attribute?&quot;)
  250. instantiate_attribute(model, model_name, attr_name, input())
  251. output(&quot;Added attribute!&quot;)
  252. else:
  253. output(&quot;No such attribute!&quot;)
  254. else:
  255. output(&quot;No such model!&quot;)
  256. elif (cmd == &quot;attr_del&quot;):
  257. String model_name
  258. output(&quot;Which model do you want to remove an attribute of?&quot;)
  259. model_name = input()
  260. if (dict_in(model[&quot;model&quot;], model_name)):
  261. Element attrs
  262. attrs = getAttributeList(model, model_name)
  263. String attr_name
  264. output(&quot;Which attribute do you want to delete?&quot;)
  265. attr_name = input()
  266. if (set_in(dict_keys(attrs), attr_name)):
  267. unset_attribute(model, model_name, attr_name)
  268. output(&quot;Attribute deleted!&quot;)
  269. else:
  270. output(&quot;No such attribute!&quot;)
  271. else:
  272. output(&quot;No such model!&quot;)
  273. elif (cmd == &quot;delete&quot;):
  274. output(&quot;What is the name of the element you want to delete?&quot;)
  275. cmd = input()
  276. if (dict_in(model[&quot;model&quot;], cmd)):
  277. model_delete_element(model, cmd)
  278. output(&quot;Deleted!&quot;)
  279. else:
  280. output(&quot;No such element; aborting&quot;)
  281. elif (cmd == &quot;rename&quot;):
  282. output(&quot;Old name?&quot;)
  283. String old_name_e
  284. old_name_e = input()
  285. if (dict_in(model[&quot;model&quot;], old_name_e)):
  286. output(&quot;New name?&quot;)
  287. String new_name_e
  288. new_name_e = input()
  289. if (dict_in(model[&quot;model&quot;], new_name_e)):
  290. output(&quot;New name already used; aborting&quot;)
  291. else:
  292. dict_add(model[&quot;model&quot;], new_name_e, model[&quot;model&quot;][old_name_e])
  293. dict_delete(model[&quot;model&quot;], old_name_e)
  294. output(&quot;Rename complete!&quot;)
  295. else:
  296. output(&quot;Unknown element; aborting&quot;)
  297. elif (cmd == &quot;list&quot;):
  298. Element keys_m
  299. keys_m = dict_keys(model[&quot;model&quot;])
  300. output(&quot;List of all elements:&quot;)
  301. String v_m
  302. while (read_nr_out(keys_m) &gt; 0):
  303. v_m = set_pop(keys_m)
  304. // Filter out anonymous objects
  305. if (bool_not(string_startswith(v_m, &quot;__&quot;))):
  306. typename = reverseKeyLookup(model[&quot;metamodel&quot;][&quot;model&quot;], dict_read_node(model[&quot;type_mapping&quot;], model[&quot;model&quot;][v_m]))
  307. output(((&quot; &quot; + v_m) + &quot; : &quot;) + typename)
  308. elif (cmd == &quot;read&quot;):
  309. output(&quot;Element to read?&quot;)
  310. cmd = input()
  311. if (dict_in(model[&quot;model&quot;], cmd)):
  312. Element read_elem
  313. read_elem = model[&quot;model&quot;][cmd]
  314. metamodel_element_pn = dict_read_node(model[&quot;type_mapping&quot;], read_elem)
  315. output(&quot;Name: &quot; + cmd)
  316. output(&quot;Type: &quot; + reverseKeyLookup(model[&quot;metamodel&quot;][&quot;model&quot;], metamodel_element_pn))
  317. if (is_edge(read_elem)):
  318. output(&quot;Source: &quot; + reverseKeyLookup(model[&quot;model&quot;], read_edge_src(read_elem)))
  319. output(&quot;Destination: &quot; + reverseKeyLookup(model[&quot;model&quot;], read_edge_dst(read_elem)))
  320. if (cast_v2s(read_elem) != &quot;None&quot;):
  321. output(&quot;Value: &quot; + cast_v2s(read_elem))
  322. output(&quot;Defines attributes:&quot;)
  323. attr_list_pn = getInstantiatableAttributes(model, read_elem)
  324. attr_keys_pn = dict_keys(attr_list_pn)
  325. while (0 &lt; read_nr_out(attr_keys_pn)):
  326. attr_key_pn = set_pop(attr_keys_pn)
  327. output((((&quot; &quot; + attr_key_pn) + &quot; : &quot;) + cast_v2s(attr_list_pn[attr_key_pn])))
  328. output(&quot;Attributes:&quot;)
  329. attr_list_pn = getAttributeList(model, cmd)
  330. attr_keys_pn = dict_keys(attr_list_pn)
  331. while (0 &lt; read_nr_out(attr_keys_pn)):
  332. attr_key_pn = set_pop(attr_keys_pn)
  333. 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)))
  334. else:
  335. output(&quot;Unknown element; aborting&quot;)
  336. elif (cmd == &quot;verify&quot;):
  337. output(conformance_scd(model))
  338. elif (cmd == &quot;types&quot;):
  339. Element keys_t
  340. keys_t = dict_keys(model[&quot;metamodel&quot;][&quot;model&quot;])
  341. output(&quot;List of types:&quot;)
  342. String v_t
  343. while (read_nr_out(keys_t) &gt; 0):
  344. v_t = set_pop(keys_t)
  345. if (bool_not(string_startswith(v_t, &quot;__&quot;))):
  346. 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]))))
  347. elif (cmd == &quot;retype&quot;):
  348. output(&quot;Element to retype?&quot;)
  349. String elementname
  350. elementname = input()
  351. if (dict_in(model[&quot;model&quot;], elementname)):
  352. output(&quot;New type&quot;)
  353. typename = input()
  354. if (dict_in(model[&quot;metamodel&quot;][&quot;model&quot;], typename)):
  355. // OK, do the retyping
  356. // First try removing the previous type if it exists
  357. dict_delete(model[&quot;type_mapping&quot;], model[&quot;model&quot;][elementname])
  358. // Now add the new type
  359. dict_add(model[&quot;type_mapping&quot;], model[&quot;model&quot;][elementname], model[&quot;metamodel&quot;][&quot;model&quot;][typename])
  360. output(&quot;Retyped!&quot;)
  361. else:
  362. output(&quot;Unknown type; aborting&quot;)
  363. else:
  364. output(&quot;Unknown element; aborting&quot;)
  365. elif (cmd == &quot;switch&quot;):
  366. bottom = bool_not(bottom)
  367. Element tmp_model
  368. tmp_model = model
  369. model = other_metamodel
  370. other_metamodel = tmp_model
  371. if (bottom):
  372. // The type mapping we are using is probably not complete for our model
  373. // so we completely recreate it from the model we have.
  374. output(&quot;Switching to conformance bottom mode!&quot;)
  375. generate_bottom_type_mapping(model)
  376. else:
  377. // We already switched the models and such, so we are already done!
  378. output(&quot;Switching to linguistic metamodel!&quot;)
  379. else:
  380. output(&quot;Unknown command: &quot; + cast_v2s(cmd))
  381. output(&quot;Use command &#39;help&#39; to get a list of available commands&quot;)
  382. Element function main():
  383. output(&quot;Welcome to the Model Management Interface, running live on the Modelverse!&quot;)
  384. output(&quot;Use &#39;help&#39; command for a list of possible commands&quot;)
  385. String command
  386. Element root
  387. Element metamodel
  388. String name
  389. Element my_model
  390. String mm_name
  391. root = create_metamodels()
  392. while (True):
  393. output(&quot;Please give your command.&quot;)
  394. command = input()
  395. if (command == &quot;help&quot;):
  396. output(&quot;Currently no model is loaded, so your operations are limited to:&quot;)
  397. output(&quot; new -- Create a new model and save it for future use&quot;)
  398. output(&quot; load -- Load a previously made model&quot;)
  399. output(&quot; rename -- Rename a previously made model&quot;)
  400. output(&quot; delete -- Delete a previously made model&quot;)
  401. output(&quot; list -- Show a list of all stored models&quot;)
  402. output(&quot; help -- Show a list of possible commands&quot;)
  403. elif (command == &quot;new&quot;):
  404. output(&quot;Metamodel to instantiate?&quot;)
  405. mm_name = input()
  406. if (dict_in(root, mm_name)):
  407. output(&quot;Name of model?&quot;)
  408. name = input()
  409. if (dict_in(root, name)):
  410. output(&quot;Model exists; aborting&quot;)
  411. else:
  412. my_model = instantiate_model(root[mm_name])
  413. dict_add(root, name, my_model)
  414. model_loaded(my_model)
  415. else:
  416. output(&quot;Unknown metamodel; aborting&quot;)
  417. elif (command == &quot;load&quot;):
  418. output(&quot;Model to load?&quot;)
  419. name = input()
  420. if (dict_in(root, name)):
  421. my_model = root[name]
  422. model_loaded(my_model)
  423. else:
  424. output(&quot;Model not found; aborting&quot;)
  425. elif (command == &quot;list&quot;):
  426. Element keys
  427. String m_menu_list
  428. keys = dict_keys(root)
  429. output(&quot;Found models:&quot;)
  430. while (read_nr_out(keys) &gt; 0):
  431. m_menu_list = set_pop(keys)
  432. output(((&quot; &quot; + m_menu_list) + &quot; : &quot;) + reverseKeyLookup(root, root[m_menu_list][&quot;metamodel&quot;]))
  433. elif (command == &quot;delete&quot;):
  434. output(&quot;Model to delete?&quot;)
  435. name = input()
  436. if (dict_in(root, name)):
  437. dict_delete(root, name)
  438. output(&quot;Deleted!&quot;)
  439. else:
  440. output(&quot;Model not found; aborting&quot;)
  441. elif (command == &quot;rename&quot;):
  442. output(&quot;Old name?&quot;)
  443. String old_name
  444. old_name = input()
  445. if (dict_in(root, old_name)):
  446. output(&quot;New name?&quot;)
  447. String new_name
  448. new_name = input()
  449. if (dict_in(root, new_name)):
  450. output(&quot;Model exists; aborting&quot;)
  451. else:
  452. dict_add(root, new_name, root[old_name])
  453. dict_delete(root, old_name)
  454. output(&quot;Rename complete!&quot;)
  455. else:
  456. output(&quot;Model not found; aborting&quot;)
  457. elif (command == &quot;actions&quot;):
  458. output(&quot;Switching to compilation manager!&quot;)
  459. compilation_manager()
  460. output(&quot;Back in model manager!&quot;)
  461. else:
  462. output(&quot;Command not recognized, use &#39;help&#39; for a list of possible commands&quot;)
  463. </pre></div>
  464. </div>
  465. <p>This code implements a very simple (meta-)modelling tool.
  466. Its use is documented with the provided <em>help</em> function.
  467. A simple example of its use is shown below.</p>
  468. <img alt="_images/prompt_pn_interface.png" src="_images/prompt_pn_interface.png" />
  469. <p>In this case, note that the value of tokens is the string 3 instead of the integer (or natural) 3.
  470. Therefore, the conformance check will flag this value as incorrectly typed.</p>
  471. </div>
  472. <div class="section" id="upload-model">
  473. <h2>Upload model<a class="headerlink" href="#upload-model" title="Permalink to this headline">¶</a></h2>
  474. <p>TODO: use the execute_model.py</p>
  475. </div>
  476. </div>
  477. </div>
  478. </div>
  479. </div>
  480. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  481. <div class="sphinxsidebarwrapper">
  482. <h3><a href="index.html">Table Of Contents</a></h3>
  483. <ul>
  484. <li><a class="reference internal" href="#">Examples</a><ul>
  485. <li><a class="reference internal" href="#fibonacci-server">Fibonacci Server</a></li>
  486. <li><a class="reference internal" href="#modelling-server">Modelling Server</a></li>
  487. <li><a class="reference internal" href="#upload-model">Upload model</a></li>
  488. </ul>
  489. </li>
  490. </ul>
  491. <h4>Previous topic</h4>
  492. <p class="topless"><a href="modellanguage.html"
  493. title="previous chapter">Modelling Language</a></p>
  494. <h4>Next topic</h4>
  495. <p class="topless"><a href="advanced.html"
  496. title="next chapter">Advanced examples</a></p>
  497. <div role="note" aria-label="source link">
  498. <h3>This Page</h3>
  499. <ul class="this-page-menu">
  500. <li><a href="_sources/examples.txt"
  501. rel="nofollow">Show Source</a></li>
  502. </ul>
  503. </div>
  504. <div id="searchbox" style="display: none" role="search">
  505. <h3>Quick search</h3>
  506. <form class="search" action="search.html" method="get">
  507. <div><input type="text" name="q" /></div>
  508. <div><input type="submit" value="Go" /></div>
  509. <input type="hidden" name="check_keywords" value="yes" />
  510. <input type="hidden" name="area" value="default" />
  511. </form>
  512. </div>
  513. <script type="text/javascript">$('#searchbox').show(0);</script>
  514. </div>
  515. </div>
  516. <div class="clearer"></div>
  517. </div>
  518. <div class="related" role="navigation" aria-label="related navigation">
  519. <h3>Navigation</h3>
  520. <ul>
  521. <li class="right" style="margin-right: 10px">
  522. <a href="genindex.html" title="General Index"
  523. >index</a></li>
  524. <li class="right" >
  525. <a href="advanced.html" title="Advanced examples"
  526. >next</a> |</li>
  527. <li class="right" >
  528. <a href="modellanguage.html" title="Modelling Language"
  529. >previous</a> |</li>
  530. <li class="nav-item nav-item-0"><a href="index.html">Modelverse 0.4.0 documentation</a> &#187;</li>
  531. </ul>
  532. </div>
  533. <div class="footer" role="contentinfo">
  534. &#169; Copyright 2016, Yentl Van Tendeloo.
  535. Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
  536. </div>
  537. </body>
  538. </html>