Preprocessing Jason

0 votes
asked May 12, 2020 in Question / help by kjw

Hi I'm trying to understand why the following gets an syntax error "

@startuml

!unquoted function DRAW($x) return %set_variable_value($x, 1)

!procedure addComponent($part, $component, $as) 

    !if %variable_exists($part) 

        participant "$component" as $as 

    !endif 

!endfunction

!procedure addBox2($part, $box, $colour, $data) 

    !if %variable_exists($part) 

        box "$box" #$colour 

            !foreach $item in $data.participants 

                $addComponent($part, "$item.name" as $item.as) 

            !endfor 

        end box 

    !endif 

!endfunction

DRAW(PART25)

!ifdef PART25 

title  TESTING  (Boxes & Participants)  Part25 

!endif

!$data={"participants" :[

{"name": "XYZ" ,"as": "xyz"},

{"name": "RST" ,"as": "rst"},

{"name": "UVW" ,"as": "uvw"}

]

}

$addBox2("PART25", "New Box", "white" ,"$data")

zyz->rst : Message()

xyz<--rst : Ack()

xyz->rst : Message2()

xyz->uvw : Message3()

@enduml

And the following doesn't

@startuml
title  TESTING  (Boxes & Participants)  Part25

box "New Box" #White
  participant XYX as xyz
  participant RST as rst
  participant UVW as uvw
end box 

xyz->rst : Message()
xyz<--rst : Ack()
xyz->rst : Message2()
xyz->uvw : Message3()
@enduml

1 Answer

0 votes
answered May 12, 2020 by The-Lu (64,340 points)

Hello Kjw,

Good example of processing, new procedure and json management...

1/ First, if you call function or procedure with '$', you must declare also with '$'.

Then change:

  • !procedure addComponent → !procedure $addComponent
  • !procedure addBox2 → !procedure $addBox2
2/ Then, beware with some double quote or typo...

 Change:

  • $addComponent($part, "$item.name" as $item.as)
    → $addComponent($part, $item.name, $item.as)
  • $addBox2("PART25", "New Box", "white" ,"$data")
    → $addBox2("PART25", "New Box", "white", $data)
  • zyz->rst : Message() → xyz->rst : Message()

With those modifications, we observe the expected result:

PlantUML diagram

If that can help,
Regards,
Th.

...