PlantUML-compatible grammar for object models¶
An instance can be generated by parsing the Object diagram defined using PlantUML Object Diagram PlantUML Object Diagram .
Let’s see an example with object diagram of the classic library model. The textual object diagram written in PlantUML Syntax is shown below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
And the object diagram produced by PlantUML is as follows.
To Parse and Load the objects you can create the test case using the following code:
from antlr4 import *
from besser.BUML.notations.od.ODLexer import ODLexer
from besser.BUML.notations.od.ODParser import ODParser
from besser.BUML.notations.od.ODListener import ODListener
def test_number_of_objects():
od = "path to Object diagram"
all_objs = []
input_stream = FileStream(od)
lexer = ODLexer(input_stream)
stream = CommonTokenStream(lexer)
parser = ODParser(stream)
tree = parser.objectDiagram()
listener = ODListener(all_objs)
walker = ParseTreeWalker()
walker.walk(listener, tree)
assert ....