Make OD-API for consistent for constraints, LHS patterns, RHS actions.

This commit is contained in:
Joeri Exelmans 2024-11-07 11:05:06 +01:00
parent 1eb8a84553
commit 9c68b288c1
8 changed files with 108 additions and 79 deletions

View file

@ -4,14 +4,16 @@ def indent(multiline_string, how_much):
lines = multiline_string.split('\n')
return '\n'.join([' '*how_much+l for l in lines])
def display_value(val: any, type_name: str, indentation=0):
def display_value(val: any, type_name: str, indentation=0, newline_character='\n'):
if type_name == "ActionCode":
if '\n' in val:
return '```\n'+indent(val, indentation+4)+'\n'+' '*indentation+'```'
orig = '```\n'+indent(val, indentation+4)+'\n'+' '*indentation+'```'
escaped = orig.replace('\n', newline_character)
return escaped
else:
return '`'+val+'`'
elif type_name == "String":
return '"'+val+'"'
return '"'+val+'"'.replace('\n', newline_character)
elif type_name == "Integer" or type_name == "Boolean":
return str(val)
else:

View file

@ -110,7 +110,8 @@ def render_object_diagram(state, m, mm, render_attributes=True, prefix_ids=""):
slot = m_od.get_slot(obj_node, attr_name)
if slot != None:
val, type_name = od.read_primitive_value(bottom, slot, mm)
output += f"\n{attr_name} => {display_value(val, type_name)}"
escaped_newline = ";"
output += f"\n{attr_name} => {display_value(val, type_name, newline_character=escaped_newline)}"
output += '\n}'
output += '\n'