mini_modify.alc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  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. if (write):
  191. if (dict_in(model["model"], element_name)):
  192. Element attrs
  193. attrs = getAttributeList(model, element_name)
  194. if (set_in(dict_keys(attrs), attr_name)):
  195. //TODO this can be more interesting if we keep the IDs in the model, thereby preventing problems with language evolution
  196. if (set_in(dict_keys(attrs), attr_name)):
  197. if (bool_not(set_in(dict_keys(attrs), new_attr_name))):
  198. // TODO use a cleaner way of deleting the attribute
  199. Boolean optional
  200. String attr_edge
  201. attr_edge = reverseKeyLookup(model["model"], dict_read_edge(model["model"][element_name], attr_name))
  202. optional = read_attribute(model, attr_edge, "optional")
  203. model_undefine_attribute(model, element_name, attr_name)
  204. model_define_attribute_ID(model, element_name, new_attr_name, optional, attrs[attr_name], attr_edge)
  205. return "Success"!
  206. else:
  207. return "Attribute already defined: " + new_attr_name!
  208. else:
  209. return "Attribute not defined: " + attr_name!
  210. return "Success"!
  211. else:
  212. return "Attribute not found: " + attr_name!
  213. else:
  214. return "Element not found: " + element_name!
  215. else:
  216. return "Permission denied to write"!
  217. String function cmd_attr_type(write : Boolean, model : Element, element_name : String, attr_name : String, new_attr_type : String):
  218. if (write):
  219. if (dict_in(model["model"], element_name)):
  220. Element attrs
  221. attrs = getAttributeList(model, element_name)
  222. if (set_in(dict_keys(attrs), attr_name)):
  223. //TODO this can be more interesting if we keep the IDs in the model, thereby preventing problems with language evolution
  224. if (set_in(dict_keys(attrs), attr_name)):
  225. // TODO use a cleaner way of deleting the attribute
  226. Boolean optional
  227. String attr_edge
  228. attr_edge = reverseKeyLookup(model["model"], dict_read_edge(model["model"][element_name], attr_name))
  229. optional = read_attribute(model, attr_edge, "optional")
  230. model_undefine_attribute(model, element_name, attr_name)
  231. model_define_attribute_ID(model, element_name, attr_name, optional, new_attr_type, attr_edge)
  232. return "Success"!
  233. else:
  234. return "Attribute not defined: " + attr_name!
  235. return "Success"!
  236. else:
  237. return "Attribute not found: " + attr_name!
  238. else:
  239. return "Element not found: " + element_name!
  240. else:
  241. return "Permission denied to write"!
  242. String function cmd_attr_optional(write : Boolean, model : Element, element_name : String, attr_name : String, optional : Boolean):
  243. if (write):
  244. if (dict_in(model["model"], element_name)):
  245. Element attrs
  246. attrs = getAttributeList(model, element_name)
  247. if (set_in(dict_keys(attrs), attr_name)):
  248. //TODO this can be more interesting if we keep the IDs in the model, thereby preventing problems with language evolution
  249. if (set_in(dict_keys(attrs), attr_name)):
  250. // TODO use a cleaner way of deleting the attribute
  251. String attr_edge
  252. attr_edge = reverseKeyLookup(model["model"], dict_read_edge(model["model"][element_name], attr_name))
  253. log("Was optional: " + cast_v2s(read_attribute(model, attr_edge, "optional")))
  254. if (optional):
  255. log("Setting to optional")
  256. else:
  257. log("Setting to mandatory")
  258. model_undefine_attribute(model, element_name, attr_name)
  259. model_define_attribute_ID(model, element_name, attr_name, optional, attrs[attr_name], attr_edge)
  260. return "Success"!
  261. else:
  262. return "Attribute not defined: " + attr_name!
  263. return "Success"!
  264. else:
  265. return "Attribute not found: " + attr_name!
  266. else:
  267. return "Element not found: " + element_name!
  268. else:
  269. return "Permission denied to write"!
  270. String function cmd_delete(write : Boolean, model : Element, element_name : String):
  271. if (write):
  272. if (dict_in(model["model"], element_name)):
  273. model_delete_element(model, element_name)
  274. return "Success"!
  275. else:
  276. return "Element not found: " + element_name!
  277. else:
  278. return "Permission denied to write"!
  279. String function cmd_list(model : Element):
  280. Element keys_m
  281. String v_m
  282. String result
  283. String typename
  284. result = "Success: "
  285. keys_m = dict_keys(model["model"])
  286. while (set_len(keys_m) > 0):
  287. v_m = set_pop(keys_m)
  288. // Filter out anonymous objects
  289. if (bool_not(string_startswith(v_m, "__"))):
  290. typename = read_type(model, v_m)
  291. result = result + " " + v_m + " : " + typename + "\n"
  292. return result!
  293. String function cmd_list_full(model : Element):
  294. Element keys_m
  295. String v_m
  296. String result
  297. String typename
  298. result = "Success: "
  299. keys_m = dict_keys(model["model"])
  300. while (set_len(keys_m) > 0):
  301. v_m = set_pop(keys_m)
  302. // Filter out anonymous objects
  303. typename = read_type(model, v_m)
  304. result = result + " " + v_m + " : " + typename + "\n"
  305. return result!
  306. String function cmd_read_outgoing(model : Element, element_name : String, type : String):
  307. String result
  308. Element elems
  309. if (dict_in(model["model"], element_name)):
  310. result = "Success: "
  311. elems = allOutgoingAssociationInstances(model, element_name, type)
  312. while (set_len(elems) > 0):
  313. result = string_join(result, set_pop(elems)) + "\n"
  314. return result!
  315. else:
  316. return "Element not found: " + element_name!
  317. String function cmd_read_incoming(model : Element, element_name : String, type : String):
  318. String result
  319. Element elems
  320. if (dict_in(model["model"], element_name)):
  321. result = "Success: "
  322. elems = allIncomingAssociationInstances(model, element_name, type)
  323. while (set_len(elems) > 0):
  324. result = string_join(result, set_pop(elems)) + "\n"
  325. return result!
  326. else:
  327. return "Element not found: " + element_name!
  328. String function cmd_connections_between(model : Element, source_name : String, target_name : String):
  329. String result
  330. Element options
  331. if (dict_in(model["model"], source_name)):
  332. if (dict_in(model["model"], target_name)):
  333. result = "Success: "
  334. options = allowedAssociationsBetween(model, source_name, target_name)
  335. while (set_len(options) > 0):
  336. result = string_join(result, set_pop(options)) + "\n"
  337. return result!
  338. else:
  339. return ("Element not found: " + target_name)!
  340. else:
  341. return ("Element not found: " + source_name)!
  342. String function cmd_read(model : Element, element_name : String):
  343. String result
  344. Element attr_list
  345. Element attr_keys
  346. String attr_key
  347. result = "Success: "
  348. if (dict_in(model["model"], element_name)):
  349. result = result + "Type: " + read_type(model, element_name) + "\n"
  350. if (is_edge(model["model"][element_name])):
  351. result = result + "Source: " + reverseKeyLookup(model["model"], read_edge_src(model["model"][element_name])) + "\n"
  352. result = result + "Destination: " + reverseKeyLookup(model["model"], read_edge_dst(model["model"][element_name])) + "\n"
  353. if (has_value(model["model"][element_name])):
  354. result = result + "Value: " + cast_v2s(model["model"][element_name]) + "\n"
  355. return result!
  356. else:
  357. return "Element not found: " + element_name!
  358. String function cmd_read_attrs(model : Element, element_name : String):
  359. String result
  360. Element attr_list
  361. Element attr_keys
  362. String attr_key
  363. result = "Success: "
  364. if (dict_in(model["model"], element_name)):
  365. attr_list = getAttributeList(model, element_name)
  366. attr_keys = dict_keys(attr_list)
  367. while (0 < set_len(attr_keys)):
  368. attr_key = set_pop(attr_keys)
  369. result = string_join(result, attr_key) + " : " + cast_v2s(attr_list[attr_key]) + " = " + cast_v2s(read_attribute(model, element_name, attr_key)) + "\n"
  370. return result!
  371. else:
  372. return "Element not found: " + element_name!
  373. String function cmd_read_defined_attrs(model : Element, element_name : String):
  374. String result
  375. Element attr_list
  376. Element attr_keys
  377. String attr_key
  378. result = "Success: "
  379. if (dict_in(model["model"], element_name)):
  380. attr_list = getInstantiatableAttributes(model, element_name, "AttributeLink")
  381. attr_keys = dict_keys(attr_list)
  382. while (0 < set_len(attr_keys)):
  383. attr_key = set_pop(attr_keys)
  384. if (value_eq(read_attribute(model, reverseKeyLookup(model["model"], dict_read_edge(model["model"][element_name], attr_key)), "optional"), True)):
  385. result = string_join(result, attr_key) + " ?: " + cast_v2s(attr_list[attr_key]) + "\n"
  386. else:
  387. result = string_join(result, attr_key) + " : " + cast_v2s(attr_list[attr_key]) + "\n"
  388. return result!
  389. else:
  390. return "Element not found: " + element_name!
  391. String function cmd_types(model : Element):
  392. Element keys_t
  393. String v_t
  394. String result
  395. keys_t = dict_keys(model["metamodel"]["model"])
  396. result = "Success: "
  397. while (set_len(keys_t) > 0):
  398. v_t = set_pop(keys_t)
  399. if (bool_not(string_startswith(v_t, "__"))):
  400. result = result + string_join(" " + v_t + " : ", read_type(model["metamodel"], v_t)) + "\n"
  401. return result!
  402. String function cmd_retype(write : Boolean, model : Element, element_name : String, new_type : String):
  403. if (write):
  404. if (dict_in(model["model"], element_name)):
  405. if (dict_in(model["metamodel"]["model"], new_type)):
  406. retype(model, element_name, new_type)
  407. return "Success"!
  408. else:
  409. return "Element not found: " + new_type!
  410. else:
  411. return "Element not found: " + element_name!
  412. else:
  413. return "Permission denied to write"!
  414. String function cmd_read_association_source(write : Boolean, model : Element, element_name : String):
  415. if (dict_in(model["model"], element_name)):
  416. if (is_edge(model["model"][element_name])):
  417. return "Success: " + readAssociationSource(model, element_name)!
  418. else:
  419. return "Not an association: " + element_name!
  420. else:
  421. return "Element not found: " + element_name!
  422. String function cmd_read_association_destination(write : Boolean, model : Element, element_name : String):
  423. if (dict_in(model["model"], element_name)):
  424. if (is_edge(model["model"][element_name])):
  425. return "Success: " + readAssociationDestination(model, element_name)!
  426. else:
  427. return "Not an association: " + element_name!
  428. else:
  429. return "Element not found: " + element_name!
  430. String function cmd_all_instances(model : Element, type : String):
  431. String result
  432. Element elems
  433. if (dict_in(model["metamodel"]["model"], type)):
  434. result = "Success: "
  435. elems = allInstances(model, type)
  436. while (set_len(elems) > 0):
  437. result = string_join(result, set_pop(elems)) + "\n"
  438. return result!
  439. else:
  440. return "Element not found: " + type!
  441. Element function modify(model : Element, write : Boolean):
  442. String cmd
  443. output("Model loaded, ready for commands!")
  444. while (True):
  445. cmd = input()
  446. if (cmd == "help"):
  447. output(cmd_help_m(write))
  448. elif (cmd == "exit"):
  449. return model!
  450. elif (cmd == "upload"):
  451. output(cmd_upload(write, model))
  452. elif (cmd == "instantiate_node"):
  453. output(cmd_instantiate_node(write, model, single_input("Type?"), single_input("Name?")))
  454. elif (cmd == "instantiate_edge"):
  455. output(cmd_instantiate_edge(write, model, single_input("Type?"), single_input("Name?"), single_input("Source?"), single_input("Target?")))
  456. elif (cmd == "attr_add"):
  457. output(cmd_attr_add(write, model, single_input("Name?"), single_input("Attribute name?"), single_input("Value?")))
  458. elif (cmd == "attr_add_code"):
  459. output(cmd_attr_add_code(write, model, single_input("Name?"), single_input("Attribute name?")))
  460. elif (cmd == "attr_del"):
  461. output(cmd_attr_del(write, model, single_input("Name?"), single_input("Attribute name?")))
  462. elif (cmd == "attr_name"):
  463. output(cmd_attr_name(write, model, single_input("Name?"), single_input("Attribute name?"), single_input("New name?")))
  464. elif (cmd == "attr_type"):
  465. output(cmd_attr_type(write, model, single_input("Name?"), single_input("Attribute name?"), single_input("Type name?")))
  466. elif (cmd == "attr_optional"):
  467. output(cmd_attr_optional(write, model, single_input("Name?"), single_input("Attribute name?"), input()))
  468. elif (cmd == "delete"):
  469. output(cmd_delete(write, model, single_input("Name?")))
  470. elif (cmd == "nice_list"):
  471. output(pretty_print(model))
  472. elif (cmd == "list"):
  473. output(cmd_list(model))
  474. elif (cmd == "list_full"):
  475. output(cmd_list_full(model))
  476. elif (cmd == "JSON"):
  477. output("Success: " + JSON_print(model))
  478. elif (cmd == "read_outgoing"):
  479. output(cmd_read_outgoing(model, single_input("Name?"), single_input("Type?")))
  480. elif (cmd == "read_incoming"):
  481. output(cmd_read_incoming(model, single_input("Name?"), single_input("Type?")))
  482. elif (cmd == "read"):
  483. output(cmd_read(model, single_input("Name?")))
  484. elif (cmd == "read_attrs"):
  485. output(cmd_read_attrs(model, single_input("Name?")))
  486. elif (cmd == "read_defined_attrs"):
  487. output(cmd_read_defined_attrs(model, single_input("Name?")))
  488. elif (cmd == "types"):
  489. output(cmd_types(model))
  490. elif (cmd == "retype"):
  491. output(cmd_retype(write, model, single_input("Name?"), single_input("New type?")))
  492. elif (cmd == "read_association_source"):
  493. output(cmd_read_association_source(write, model, single_input("Name?")))
  494. elif (cmd == "read_association_destination"):
  495. output(cmd_read_association_destination(write, model, single_input("Name?")))
  496. elif (cmd == "connections_between"):
  497. output(cmd_connections_between(model, single_input("Source element?"), single_input("Target element?")))
  498. elif (cmd == "all_instances"):
  499. output(cmd_all_instances(model, single_input("Type?")))
  500. elif (cmd == "define_attribute"):
  501. output(cmd_define_attribute(write, model, single_input("On which element?"), single_input("Attribute name?"), single_input("Type?")))
  502. else:
  503. output("Unknown command while modelling: " + cmd)
  504. output("Use command 'help' to get a list of available commands")
  505. return model!
  506. String function single_input(prompt : String):
  507. if (verbose):
  508. output(prompt)
  509. return input()!
  510. Element function set_input(prompt : String):
  511. Element result
  512. Element inp
  513. if (verbose):
  514. output(prompt)
  515. output("-- Set input: empty string to terminate set")
  516. result = set_create()
  517. while (True):
  518. inp = input()
  519. if (value_eq(inp, "")):
  520. return result!
  521. else:
  522. set_add(result, inp)
  523. Element function dict_input(prompt : String):
  524. Element result
  525. Element key
  526. if (verbose):
  527. output(prompt)
  528. output("-- Dict input: empty key to terminate dict")
  529. result = set_create()
  530. while (True):
  531. key = input()
  532. if (value_eq(key, "")):
  533. return result!
  534. else:
  535. dict_add(result, key, input())
  536. Void function set_verbose(v : Boolean):
  537. verbose = v
  538. return!