mini_modify.alc 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. include "primitives.alh"
  2. include "constructors.alh"
  3. include "object_operations.alh"
  4. include "library.alh"
  5. include "conformance_scd.alh"
  6. include "io.alh"
  7. include "metamodels.alh"
  8. include "modelling.alh"
  9. include "typing.alh"
  10. include "compiler.alh"
  11. include "utils.alh"
  12. Boolean verbose = True
  13. String function pretty_print(model : Element):
  14. Element keys_m
  15. String type
  16. String v_m
  17. Element attr_list
  18. Element attr_keys
  19. String attr_key
  20. String result
  21. Element lst
  22. String assoc
  23. result = ""
  24. keys_m = dict_keys(model["model"])
  25. while (set_len(keys_m) > 0):
  26. v_m = set_pop(keys_m)
  27. type = read_type(model["metamodel"], read_type(model, v_m))
  28. if (bool_or(type == "Class", type == "Association")):
  29. result = result + " " + v_m + " : " + read_type(model, v_m)
  30. result = result + "\n"
  31. if (type == "Association"):
  32. result = result + " " + reverseKeyLookup(model["model"], read_edge_src(model["model"][v_m])) + " --> " + reverseKeyLookup(model["model"], read_edge_dst(model["model"][v_m]))
  33. result = result + "\n"
  34. // Print all incoming associations
  35. result = result + " Incoming associations:\n"
  36. lst = allIncomingAssociationInstances(model, v_m, "")
  37. while (set_len(lst) > 0):
  38. assoc = set_pop(lst)
  39. if (read_type(model["metamodel"], read_type(model, assoc)) == "Association"):
  40. result = result + " " + readAssociationSource(model, assoc) + " : " + read_type(model, readAssociationSource(model, assoc)) + " ---(" + assoc + " : " + read_type(model, assoc) + ")--> \n"
  41. // Print all outgoing associations
  42. result = result + " Outgoing associations:\n"
  43. lst = allOutgoingAssociationInstances(model, v_m, "")
  44. while (set_len(lst) > 0):
  45. assoc = set_pop(lst)
  46. if (read_type(model["metamodel"], read_type(model, assoc)) == "Association"):
  47. result = result + " ---(" + assoc + " : " + read_type(model, assoc) + ")--> " + readAssociationDestination(model, assoc) + " : " + read_type(model, readAssociationDestination(model, assoc)) + "\n"
  48. // Defines attributes
  49. result = result + " Defines attributes:\n"
  50. attr_list = getInstantiatableAttributes(model, v_m, "AttributeLink")
  51. attr_keys = dict_keys(attr_list)
  52. while (set_len(attr_keys) > 0):
  53. attr_key = set_pop(attr_keys)
  54. result = result + " " + attr_key + " : " + cast_value(attr_list[attr_key])
  55. result = result + "\n"
  56. // Has attributes
  57. result = result + " Has attributes:\n"
  58. attr_list = getAttributeList(model, v_m)
  59. attr_keys = dict_keys(attr_list)
  60. while (set_len(attr_keys) > 0):
  61. attr_key = set_pop(attr_keys)
  62. if (element_eq(read_attribute(model, v_m, attr_key), read_root())):
  63. result = result + " " + cast_string(attr_key) + " : " + cast_string(attr_list[attr_key]) + " = (undefined)"
  64. else:
  65. result = result + " " + cast_string(attr_key) + " : " + cast_string(attr_list[attr_key]) + " = " + cast_value(read_attribute(model, v_m, attr_key))
  66. result = result + "\n"
  67. else:
  68. log("Skip instance: " + type)
  69. return result!
  70. String function cmd_help_m(write : Boolean):
  71. String result
  72. result = ""
  73. result = result + "Allowed operations:\n"
  74. if (write):
  75. result = result + " == READ/WRITE ==\n"
  76. result = result + " instantiate_node -- Create a new model element (node)\n"
  77. result = result + " instantiate_edge -- Create a new model element (edge)\n"
  78. result = result + " delete -- Delete an existing element\n"
  79. result = result + " attr_add -- Add an attribute to an element\n"
  80. result = result + " attr_add_code -- Add a coded attribute to an element\n"
  81. result = result + " attr_del -- Delete an attribute of an element\n"
  82. result = result + " attr_modify -- Modify an attribute of an element\n"
  83. result = result + " retype -- Change the type of an element\n"
  84. result = result + " upload -- Upload a completely new model\n"
  85. else:
  86. result = result + " == READ-ONLY ==\n"
  87. result = result + " read_outgoing -- Prints the list of outgoing links of an element\n"
  88. result = result + " read_incoming -- Prints the list of incoming links to an element\n"
  89. result = result + " list -- Prints the list of elements in the model\n"
  90. result = result + " list_full -- Prints the list of all elements in the model\n"
  91. result = result + " types -- Prints the list of elements that can be instantiated\n"
  92. result = result + " read -- Prints the current state of a model element\n"
  93. result = result + " verify -- Check whether the model conforms to the metamodel\n"
  94. result = result + " exit -- Leave the modification interface\n"
  95. return result!
  96. String function cmd_upload(write : Boolean, model : Element):
  97. Element new_model
  98. if (write):
  99. output("Waiting for model constructors...")
  100. new_model = compile_model(input(), model["metamodel"])
  101. if (element_eq(new_model, read_root())):
  102. return "Compilation error"!
  103. dict_overwrite(model, "model", new_model["model"])
  104. set_type_mapping(model, get_type_mapping(new_model))
  105. return "Success"!
  106. else:
  107. return "Permission denied to write"!
  108. String function cmd_instantiate_node(write : Boolean, model : Element, mm_type_name : String, element_name : String):
  109. if (write):
  110. if (dict_in(model["metamodel"]["model"], mm_type_name)):
  111. if (dict_in(model["model"], element_name)):
  112. return "Element exists: " + element_name!
  113. else:
  114. if (is_edge(model["metamodel"]["model"][mm_type_name])):
  115. return "Element is not a node but an edge: " + mm_type_name!
  116. element_name = instantiate_node(model, mm_type_name, element_name)
  117. return "Success: " + element_name!
  118. else:
  119. return "Element not found: " + mm_type_name!
  120. else:
  121. return "Permission denied to write"!
  122. String function cmd_instantiate_edge(write : Boolean, model : Element, mm_type_name : String, element_name : String, source_name : String, target_name : String):
  123. if (write):
  124. if (dict_in(model["metamodel"]["model"], mm_type_name)):
  125. if (dict_in(model["model"], element_name)):
  126. return "Element exists: " + element_name!
  127. else:
  128. if (is_edge(model["metamodel"]["model"][mm_type_name])):
  129. if (dict_in(model["model"], source_name)):
  130. if (dict_in(model["model"], target_name)):
  131. element_name = instantiate_link(model, mm_type_name, element_name, source_name, target_name)
  132. return "Success: " + element_name!
  133. else:
  134. return "Element not found: " + target_name!
  135. else:
  136. return "Element not found: " + source_name!
  137. else:
  138. return "Element is a node not an edge: " + mm_type_name!
  139. else:
  140. return "Element not found: " + mm_type_name!
  141. else:
  142. return "Permission denied to write"!
  143. String function cmd_define_attribute(write : Boolean, model : Element, element_name : String, attr_name : String, type : String):
  144. if (write):
  145. if (dict_in(model["model"], element_name)):
  146. if (dict_in(model["model"], type)):
  147. Element attrs
  148. attrs = getInstantiatableAttributes(model, element_name, "AttributeLink")
  149. if (bool_not(set_in(dict_keys(attrs), attr_name))):
  150. model_define_attribute(model, element_name, attr_name, False, type)
  151. return "Success"!
  152. else:
  153. return "Attribute already defined: " + attr_name!
  154. else:
  155. return "Element not found: " + type!
  156. else:
  157. return "Element not found: " + element_name!
  158. else:
  159. return "Permission denied to write"!
  160. String function cmd_attr_add(write : Boolean, model : Element, element_name : String, attr_name : String, value : Element):
  161. if (write):
  162. if (dict_in(model["model"], element_name)):
  163. Element attrs
  164. attrs = getAttributeList(model, element_name)
  165. if (set_in(dict_keys(attrs), attr_name)):
  166. instantiate_attribute(model, element_name, attr_name, value)
  167. return "Success"!
  168. else:
  169. return "Attribute not found: " + attr_name!
  170. else:
  171. return "Element not found: " + element_name!
  172. else:
  173. return "Permission denied to write"!
  174. String function cmd_attr_add_code(write : Boolean, model : Element, element_name : String, attr_name : String):
  175. if (write):
  176. if (dict_in(model["model"], element_name)):
  177. Element attrs
  178. attrs = getAttributeList(model, element_name)
  179. if (set_in(dict_keys(attrs), attr_name)):
  180. output("Waiting for code constructors...")
  181. Element compiled
  182. compiled = compile_code(input())
  183. if (element_eq(compiled, read_root())):
  184. return "Compilation error"!
  185. instantiate_attribute_code(model, element_name, attr_name, compiled)
  186. return "Success"!
  187. else:
  188. return "Attribute not found: " + attr_name!
  189. else:
  190. return "Element not found: " + element_name!
  191. else:
  192. return "Permission denied to write"!
  193. String function cmd_attr_del(write : Boolean, model : Element, element_name : String, attr_name : String):
  194. if (write):
  195. if (dict_in(model["model"], element_name)):
  196. Element attrs
  197. attrs = getAttributeList(model, element_name)
  198. if (set_in(dict_keys(attrs), attr_name)):
  199. unset_attribute(model, element_name, attr_name)
  200. return "Success"!
  201. else:
  202. return "Attribute not found: " + attr_name!
  203. else:
  204. return "Element not found: " + element_name!
  205. else:
  206. return "Permission denied to write"!
  207. String function cmd_attr_name(write : Boolean, model : Element, element_name : String, attr_name : String, new_attr_name : String):
  208. if (write):
  209. if (dict_in(model["model"], element_name)):
  210. Element attrs
  211. attrs = getInstantiatableAttributes(model, element_name, "AttributeLink")
  212. if (set_in(dict_keys(attrs), attr_name)):
  213. if (set_in(dict_keys(attrs), attr_name)):
  214. if (bool_not(set_in(dict_keys(attrs), new_attr_name))):
  215. Boolean optional
  216. String attr_edge
  217. attr_edge = reverseKeyLookup(model["model"], dict_read_edge(model["model"][element_name], attr_name))
  218. optional = read_attribute(model, attr_edge, "optional")
  219. model_undefine_attribute(model, element_name, attr_name)
  220. model_define_attribute_ID(model, element_name, new_attr_name, optional, attrs[attr_name], attr_edge)
  221. return "Success"!
  222. else:
  223. return "Attribute already defined: " + new_attr_name!
  224. else:
  225. return "Attribute not defined: " + attr_name!
  226. else:
  227. return "Attribute not found: " + attr_name!
  228. else:
  229. return "Element not found: " + element_name!
  230. else:
  231. return "Permission denied to write"!
  232. String function cmd_attr_type(write : Boolean, model : Element, element_name : String, attr_name : String, new_attr_type : String):
  233. if (write):
  234. if (dict_in(model["model"], element_name)):
  235. Element attrs
  236. attrs = getInstantiatableAttributes(model, element_name, "AttributeLink")
  237. if (set_in(dict_keys(attrs), attr_name)):
  238. if (set_in(dict_keys(attrs), attr_name)):
  239. Boolean optional
  240. String attr_edge
  241. attr_edge = reverseKeyLookup(model["model"], dict_read_edge(model["model"][element_name], attr_name))
  242. optional = read_attribute(model, attr_edge, "optional")
  243. model_undefine_attribute(model, element_name, attr_name)
  244. model_define_attribute_ID(model, element_name, attr_name, optional, new_attr_type, attr_edge)
  245. return "Success"!
  246. else:
  247. return "Attribute not defined: " + attr_name!
  248. else:
  249. return "Attribute not found: " + attr_name!
  250. else:
  251. return "Element not found: " + element_name!
  252. else:
  253. return "Permission denied to write"!
  254. String function cmd_attr_optional(write : Boolean, model : Element, element_name : String, attr_name : String, optional : Boolean):
  255. if (write):
  256. if (dict_in(model["model"], element_name)):
  257. Element attrs
  258. attrs = getInstantiatableAttributes(model, element_name, "AttributeLink")
  259. if (set_in(dict_keys(attrs), attr_name)):
  260. if (set_in(dict_keys(attrs), attr_name)):
  261. String attr_edge
  262. attr_edge = reverseKeyLookup(model["model"], dict_read_edge(model["model"][element_name], attr_name))
  263. if (optional):
  264. log("Setting to optional")
  265. else:
  266. log("Setting to mandatory")
  267. model_undefine_attribute(model, element_name, attr_name)
  268. model_define_attribute_ID(model, element_name, attr_name, optional, attrs[attr_name], attr_edge)
  269. return "Success"!
  270. else:
  271. return "Attribute not defined: " + attr_name!
  272. else:
  273. return "Attribute not found: " + attr_name!
  274. else:
  275. return "Element not found: " + element_name!
  276. else:
  277. return "Permission denied to write"!
  278. String function cmd_undefine_attribute(write : Boolean, model : Element, element_name : String, attr_name : String):
  279. if (write):
  280. if (dict_in(model["model"], element_name)):
  281. Element attrs
  282. attrs = getInstantiatableAttributes(model, element_name, "AttributeLink")
  283. if (set_in(dict_keys(attrs), attr_name)):
  284. if (set_in(dict_keys(attrs), attr_name)):
  285. model_undefine_attribute(model, element_name, attr_name)
  286. log("REMOVE OK")
  287. return "Success"!
  288. else:
  289. return "Attribute not defined: " + attr_name!
  290. else:
  291. return "Attribute not found: " + attr_name!
  292. else:
  293. return "Element not found: " + element_name!
  294. else:
  295. return "Permission denied to write"!
  296. String function cmd_delete(write : Boolean, model : Element, element_name : String):
  297. if (write):
  298. if (dict_in(model["model"], element_name)):
  299. model_delete_element(model, element_name)
  300. return "Success"!
  301. else:
  302. return "Element not found: " + element_name!
  303. else:
  304. return "Permission denied to write"!
  305. String function cmd_list(model : Element):
  306. Element keys_m
  307. String v_m
  308. String result
  309. String typename
  310. result = "Success: "
  311. keys_m = dict_keys(model["model"])
  312. while (set_len(keys_m) > 0):
  313. v_m = set_pop(keys_m)
  314. // Filter out anonymous objects
  315. if (bool_not(string_startswith(v_m, "__"))):
  316. typename = read_type(model, v_m)
  317. result = result + " " + v_m + " : " + typename + "\n"
  318. return result!
  319. String function cmd_list_full(model : Element):
  320. Element keys_m
  321. String v_m
  322. String result
  323. String typename
  324. result = "Success: "
  325. keys_m = dict_keys(model["model"])
  326. while (set_len(keys_m) > 0):
  327. v_m = set_pop(keys_m)
  328. // Filter out anonymous objects
  329. typename = read_type(model, v_m)
  330. result = result + " " + v_m + " : " + typename + "\n"
  331. return result!
  332. String function cmd_read_outgoing(model : Element, element_name : String, type : String):
  333. String result
  334. Element elems
  335. if (dict_in(model["model"], element_name)):
  336. result = "Success: "
  337. elems = allOutgoingAssociationInstances(model, element_name, type)
  338. while (set_len(elems) > 0):
  339. result = string_join(result, set_pop(elems)) + "\n"
  340. return result!
  341. else:
  342. return "Element not found: " + element_name!
  343. String function cmd_read_incoming(model : Element, element_name : String, type : String):
  344. String result
  345. Element elems
  346. if (dict_in(model["model"], element_name)):
  347. result = "Success: "
  348. elems = allIncomingAssociationInstances(model, element_name, type)
  349. while (set_len(elems) > 0):
  350. result = string_join(result, set_pop(elems)) + "\n"
  351. return result!
  352. else:
  353. return "Element not found: " + element_name!
  354. String function cmd_connections_between(model : Element, source_name : String, target_name : String):
  355. String result
  356. Element options
  357. if (dict_in(model["model"], source_name)):
  358. if (dict_in(model["model"], target_name)):
  359. result = "Success: "
  360. options = allowedAssociationsBetween(model, source_name, target_name)
  361. while (set_len(options) > 0):
  362. result = string_join(result, set_pop(options)) + "\n"
  363. return result!
  364. else:
  365. return ("Element not found: " + target_name)!
  366. else:
  367. return ("Element not found: " + source_name)!
  368. String function cmd_read(model : Element, element_name : String):
  369. String result
  370. Element attr_list
  371. Element attr_keys
  372. String attr_key
  373. result = "Success: "
  374. if (dict_in(model["model"], element_name)):
  375. result = result + "Type: " + read_type(model, element_name) + "\n"
  376. if (is_edge(model["model"][element_name])):
  377. result = result + "Source: " + reverseKeyLookup(model["model"], read_edge_src(model["model"][element_name])) + "\n"
  378. result = result + "Destination: " + reverseKeyLookup(model["model"], read_edge_dst(model["model"][element_name])) + "\n"
  379. if (has_value(model["model"][element_name])):
  380. result = result + "Value: " + cast_value(model["model"][element_name]) + "\n"
  381. return result!
  382. else:
  383. return "Element not found: " + element_name!
  384. String function cmd_read_attrs(model : Element, element_name : String):
  385. String result
  386. Element attr_list
  387. Element attr_keys
  388. String attr_key
  389. result = "Success: "
  390. if (dict_in(model["model"], element_name)):
  391. attr_list = getAttributeList(model, element_name)
  392. attr_keys = dict_keys(attr_list)
  393. while (0 < set_len(attr_keys)):
  394. attr_key = set_pop(attr_keys)
  395. result = string_join(result, attr_key) + " : " + cast_value(attr_list[attr_key]) + " = " + cast_value(read_attribute(model, element_name, attr_key)) + "\n"
  396. return result!
  397. else:
  398. return "Element not found: " + element_name!
  399. String function cmd_read_defined_attrs(model : Element, element_name : String):
  400. String result
  401. Element attr_list
  402. Element attr_keys
  403. String attr_key
  404. result = "Success: "
  405. if (dict_in(model["model"], element_name)):
  406. attr_list = getInstantiatableAttributes(model, element_name, "AttributeLink")
  407. attr_keys = dict_keys(attr_list)
  408. while (0 < set_len(attr_keys)):
  409. attr_key = set_pop(attr_keys)
  410. if (value_eq(read_attribute(model, reverseKeyLookup(model["model"], dict_read_edge(model["model"][element_name], attr_key)), "optional"), True)):
  411. result = string_join(result, attr_key) + " ?: " + cast_value(attr_list[attr_key]) + "\n"
  412. else:
  413. result = string_join(result, attr_key) + " : " + cast_value(attr_list[attr_key]) + "\n"
  414. return result!
  415. else:
  416. return "Element not found: " + element_name!
  417. String function cmd_types(model : Element):
  418. Element keys_t
  419. String v_t
  420. String result
  421. keys_t = dict_keys(model["metamodel"]["model"])
  422. result = "Success: "
  423. while (set_len(keys_t) > 0):
  424. v_t = set_pop(keys_t)
  425. if (bool_not(string_startswith(v_t, "__"))):
  426. result = result + string_join(" " + v_t + " : ", read_type(model["metamodel"], v_t)) + "\n"
  427. return result!
  428. String function cmd_retype(write : Boolean, model : Element, element_name : String, new_type : String):
  429. if (write):
  430. if (dict_in(model["model"], element_name)):
  431. if (dict_in(model["metamodel"]["model"], new_type)):
  432. retype(model, element_name, new_type)
  433. return "Success"!
  434. else:
  435. return "Element not found: " + new_type!
  436. else:
  437. return "Element not found: " + element_name!
  438. else:
  439. return "Permission denied to write"!
  440. String function cmd_read_association_source(write : Boolean, model : Element, element_name : String):
  441. if (dict_in(model["model"], element_name)):
  442. if (is_edge(model["model"][element_name])):
  443. return "Success: " + readAssociationSource(model, element_name)!
  444. else:
  445. return "Not an association: " + element_name!
  446. else:
  447. return "Element not found: " + element_name!
  448. String function cmd_read_association_destination(write : Boolean, model : Element, element_name : String):
  449. if (dict_in(model["model"], element_name)):
  450. if (is_edge(model["model"][element_name])):
  451. return "Success: " + readAssociationDestination(model, element_name)!
  452. else:
  453. return "Not an association: " + element_name!
  454. else:
  455. return "Element not found: " + element_name!
  456. String function cmd_all_instances(model : Element, type : String):
  457. String result
  458. Element elems
  459. if (dict_in(model["metamodel"]["model"], type)):
  460. result = "Success: "
  461. elems = allInstances(model, type)
  462. while (set_len(elems) > 0):
  463. result = string_join(result, set_pop(elems)) + "\n"
  464. return result!
  465. else:
  466. return "Element not found: " + type!
  467. Element function modify(model : Element, write : Boolean):
  468. String cmd
  469. output("Model loaded, ready for commands!")
  470. while (True):
  471. cmd = input()
  472. if (cmd == "help"):
  473. output(cmd_help_m(write))
  474. elif (cmd == "exit"):
  475. return model!
  476. elif (cmd == "upload"):
  477. output(cmd_upload(write, model))
  478. elif (cmd == "instantiate_node"):
  479. output(cmd_instantiate_node(write, model, single_input("Type?"), single_input("Name?")))
  480. elif (cmd == "instantiate_edge"):
  481. output(cmd_instantiate_edge(write, model, single_input("Type?"), single_input("Name?"), single_input("Source?"), single_input("Target?")))
  482. elif (cmd == "attr_add"):
  483. output(cmd_attr_add(write, model, single_input("Name?"), single_input("Attribute name?"), single_input("Value?")))
  484. elif (cmd == "attr_add_code"):
  485. output(cmd_attr_add_code(write, model, single_input("Name?"), single_input("Attribute name?")))
  486. elif (cmd == "attr_del"):
  487. output(cmd_attr_del(write, model, single_input("Name?"), single_input("Attribute name?")))
  488. elif (cmd == "attr_name"):
  489. output(cmd_attr_name(write, model, single_input("Name?"), single_input("Attribute name?"), single_input("New name?")))
  490. elif (cmd == "attr_type"):
  491. output(cmd_attr_type(write, model, single_input("Name?"), single_input("Attribute name?"), single_input("Type name?")))
  492. elif (cmd == "attr_optional"):
  493. output(cmd_attr_optional(write, model, single_input("Name?"), single_input("Attribute name?"), input()))
  494. elif (cmd == "delete"):
  495. output(cmd_delete(write, model, single_input("Name?")))
  496. elif (cmd == "nice_list"):
  497. output(pretty_print(model))
  498. elif (cmd == "list"):
  499. output(cmd_list(model))
  500. elif (cmd == "list_full"):
  501. output(cmd_list_full(model))
  502. elif (cmd == "JSON"):
  503. output("Success: " + JSON_print(model))
  504. elif (cmd == "read_outgoing"):
  505. output(cmd_read_outgoing(model, single_input("Name?"), single_input("Type?")))
  506. elif (cmd == "read_incoming"):
  507. output(cmd_read_incoming(model, single_input("Name?"), single_input("Type?")))
  508. elif (cmd == "read"):
  509. output(cmd_read(model, single_input("Name?")))
  510. elif (cmd == "read_attrs"):
  511. output(cmd_read_attrs(model, single_input("Name?")))
  512. elif (cmd == "read_defined_attrs"):
  513. output(cmd_read_defined_attrs(model, single_input("Name?")))
  514. elif (cmd == "types"):
  515. output(cmd_types(model))
  516. elif (cmd == "retype"):
  517. output(cmd_retype(write, model, single_input("Name?"), single_input("New type?")))
  518. elif (cmd == "read_association_source"):
  519. output(cmd_read_association_source(write, model, single_input("Name?")))
  520. elif (cmd == "read_association_destination"):
  521. output(cmd_read_association_destination(write, model, single_input("Name?")))
  522. elif (cmd == "connections_between"):
  523. output(cmd_connections_between(model, single_input("Source element?"), single_input("Target element?")))
  524. elif (cmd == "all_instances"):
  525. output(cmd_all_instances(model, single_input("Type?")))
  526. elif (cmd == "define_attribute"):
  527. output(cmd_define_attribute(write, model, single_input("On which element?"), single_input("Attribute name?"), single_input("Type?")))
  528. elif (cmd == "undefine_attribute"):
  529. output(cmd_undefine_attribute(write, model, single_input("On which element?"), single_input("Attribute name?")))
  530. else:
  531. output("Unknown command while modelling: " + cast_value(cmd))
  532. output("Use command 'help' to get a list of available commands")
  533. return model!
  534. String function single_input(prompt : String):
  535. if (verbose):
  536. output(prompt)
  537. return input()!
  538. Element function set_input(prompt : String):
  539. Element result
  540. Element inp
  541. if (verbose):
  542. output(prompt)
  543. output("-- Set input: empty string to terminate set")
  544. result = set_create()
  545. while (True):
  546. inp = input()
  547. if (value_eq(inp, "")):
  548. return result!
  549. else:
  550. set_add(result, inp)
  551. Element function dict_input(prompt : String):
  552. Element result
  553. Element key
  554. if (verbose):
  555. output(prompt)
  556. output("-- Dict input: empty key to terminate dict")
  557. result = set_create()
  558. while (True):
  559. key = input()
  560. if (value_eq(key, "")):
  561. return result!
  562. else:
  563. dict_add(result, key, input())
  564. Void function set_verbose(v : Boolean):
  565. verbose = v
  566. return!