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@startuml
 2Object Library {
 3name: "dummy"
 4address: "dummy"
 5}
 6
 7Object Bookone {
 8tittle: "not important"
 9pages: 10
10release: 01/01/2001
11}
12
13Object Author {
14name: "dummy"
15email: "dummy@dummy.com"
16}
17
18Object Booktwo {
19tittle: "not important"
20pages: 20
21release: 01/01/2001
22}
23
24Object Bookthree {
25tittle: "not important"
26pages: 30
27release: 01/01/2001
28}
29
30Booktwo --> Author :wrote
31Bookthree --> Author :wrote
32Bookone --> Author :wrote
33
34Library --> Bookone :has
35Library --> Booktwo :has
36Library --> Bookthree:has
37@enduml

And the object diagram produced by PlantUML is as follows.

Object diagram Library model

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 ....