mini_modify.alc 22 KB

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