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
@startuml
Object Library {
name: "dummy"
address: "dummy"
}

Object Bookone {
tittle: "not important"
pages: 10
release: 01/01/2001
}

Object Author {
name: "dummy"
email: "dummy@dummy.com"
}

Object Booktwo {
tittle: "not important"
pages: 20
release: 01/01/2001
}

Object Bookthree {
tittle: "not important"
pages: 30
release: 01/01/2001
}

Booktwo --> Author :wrote
Bookthree --> Author :wrote
Bookone --> Author :wrote

Library --> Bookone :has
Library --> Booktwo :has
Library --> Bookthree:has
@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 ....