PlantUML: render class cardinalities. Extend constraint checker API.

This commit is contained in:
Joeri Exelmans 2024-10-08 21:08:06 +02:00
parent c351649d23
commit e70eae2286
9 changed files with 252 additions and 142 deletions

View file

@ -23,10 +23,19 @@ def render_class_diagram(state, model, prefix_ids=""):
if slot != None:
is_abstract, _ = od.read_primitive_value(bottom, slot, model_od.type_model)
if is_abstract:
output += f"\nabstract class \"{name}\" as {make_id(class_node)}"
lower_card, upper_card = model_scd.get_class_cardinalities(class_node)
if lower_card == None and upper_card == None:
card_spec = ""
else:
output += f"\nclass \"{name}\" as {make_id(class_node)}"
card_spec = f"{0 if lower_card == None else lower_card}..{"*" if upper_card == None else upper_card}"
if is_abstract:
output += f"\nabstract class \"{name} {card_spec}\" as {make_id(class_node)}"
else:
output += f"\nclass \"{name} {card_spec}\" as {make_id(class_node)}"
# Render attributes
output += " {"

View file

@ -29,8 +29,11 @@ BOOL: "True" | "False"
CODE: /`[^`]*`/
INDENTED_CODE: /```[^`]*```/
object: [IDENTIFIER] ":" IDENTIFIER [link_spec] ["{" slot* "}"]
# name (optional) type
object: [IDENTIFIER] ":" IDENTIFIER [link_spec] ["{" slot* "}"]
link_spec: "(" IDENTIFIER "->" IDENTIFIER ")"
slot: IDENTIFIER "=" literal ";"
"""
@ -78,7 +81,7 @@ def parse_od(state, cs_text, mm):
space_count += 1
lines = token.split('\n')[1:-1]
for line in lines:
if line[0:space_count] != ' '*space_count:
if len(line) >= space_count and line[0:space_count] != ' '*space_count:
raise Exception("wrong indentation of INDENTED_CODE")
unindented_lines = [l[space_count:] for l in lines]
return _Code('\n'.join(unindented_lines))