Function Result generating a syntax error

0 votes
asked May 2, 2020 in Question / help by gobravedave (200 points)

Hello plantuml,

I have written a function which looks up a value in a json structure and returns a result string I was hoping would be rendered into a PlantUML C4 Model diagram as per C4-PlantUML https://github.com/RicardoNiepel/C4-PlantUML

The function appears to be working, however the result generates a syntax error. I suspect it is an issue with the order of processing of the include files.

please see link to example of the code and the error.

Also, you may notice I am returning single quotes in the response.. Is there a way to return a double quotes?

http://www.plantuml.com/plantuml/uml/lPDHQzim4CVVzIakmYCnI-qDzXG85D8-3BeoLleqHZXBbqGWovvqsXYbttsoahWrP4-3FaNwtzrF_xkShmEZvzXQCOlkP-oODEoYKsmw1mNs_Q8mkXGpuvIDcgAtS63kmwgkFVwkzeOFiOc1lEeSa-DATMtzpIZqkhitr9EjDv-klbfq_FZbhlPa2GFL7wy-97sxIKLe7FcgpnOAZOph9zcZPwDCdwg2XDLt44_IQBa2gLe9Iscn8PklCN3NaeSM0vENIwafg27IeiCz1JXd1Fcy72ayfR175_3OSwwxI7gLDO7X58PATT7nlnsT4X93_13FOhRhFA4wG35q3SP1daBrUWO2O6PsnupAQ5YleJ0wgLdNb4AVxpTtZpUtsvlRXqqAv90dZjw1VFWJcDg5XFSZ8Xtb4kOlKlO_g7EOw8FxB9SIZW-I3VH_BvJoH7BQxCHu67xICCH5wWWan-GXmn8e5vqNLhpHdehvkq2y_ONUO6Cf7MoaXPpy1ybgmJvIASIf3SJa7X52lixBizuqIM-QipvSpFubAt-4myOcqZKvdGpy1G00

thanks,
David.

2 Answers

+1 vote
answered May 3, 2020 by The-Lu (37,800 points)
selected May 3, 2020 by gobravedave
 
Best answer

Hello David,

In addition of my comment (https://forum.plantuml.net/11402/function-result-generating-a-syntax-error?show=11409#c11409), with :

  1. Use of Procedure (see green color)
  2. Boolean management (for INCLUDE_DESC see violet color, for $id_exist see blue color)

We obtain:

@startuml
!unquoted procedure $app($id)
!includeurl https://raw.githubusercontent.com/RicardoNiepel/C4-PlantUML/release/1-0/C4_Container.puml
!$data={"participants" :[
{"id": "cm" ,"label": "customer master","desc": "manages customers"},
{"id": "tm" ,"label": "transaction manager","desc": "manages transactions"},
{"id": "am" ,"label": "account master","desc": "manages accounts"}
]
}
!$id_exist = %false()
!foreach $part in $data.participants
  !if $part.id == $id
    !$id_exist = %true()
    !if $INCLUDE_DESC
       System($part.id, $part.label, $part.desc)
    !else
       System($part.id, $part.label)
    !endif
  !endif
!endfor
!if %not($id_exist)
System($id, "enter label for <u:red>$id")
!endif
!endprocedure

!includeurl https://raw.githubusercontent.com/RicardoNiepel/C4-PlantUML/release/1-0/C4_Container.puml

%set_variable_value("$INCLUDE_DESC", %true())

System(aa, "aa system")
System(bb, "bb system", "big system")
$app(tm)
$app(am)
$app(Xm)
@enduml


[Click on the image to view code]

If that can help,
Regards,
Th.

commented May 3, 2020 by gobravedave (200 points)
thank you very much @The-Lu.. Indeed your response if very helpful.
0 votes
answered May 2, 2020 by plantuml (264,940 points)
Indeed, there seems to be an issue here...

Could you build a shorter example (that is, without any !include) that shows the issue ?

This would definitively help...

Thanks!
commented May 2, 2020 by gobravedave (200 points)
edited May 2, 2020 by gobravedave

@startuml
!unquoted function $app($id)
      !return "System(" + $id + ", 'label' , 'description')"
!endfunction

!includeurl https://raw.githubusercontent.com/RicardoNiepel/C4-PlantUML/release/1-0/C4_Container.puml
System(aa, 'aa system')
System(bb, 'bb system', 'big system')
$app("tm")

@enduml

http://www.plantuml.com/plantuml/uml/HOz1IyGm48Nl-HLfMEWMtKR1awU5lQg8ubacoRWRIATnCa7yzwR5iZc4l2ypZ_UEHO2bJabrbRxhB1ZqLoKlSIQzWvptknW6fTVJCKfbqkRzjmXEUwDlTFjkjxdLVGA7gTVj5R1uZddnw0UZEgImUIhLHVAf1goSz4KabqTh6Nx6SvHBTRKW-va4IKO_J_OjUk0mlqJCcEpfuV2QWEJZ-Sao9eI2zlvmr_ZdgIr19EGnBst-4mAqE02whB8VDkvSuyvjV17nV9rQYnkPpA3K4Iaqnpy0

The log shows how the scripted C4 Systems are converted to rectangles.. however the output from the functional has not.

commented May 2, 2020 by The-Lu (37,800 points)

Hello David,

Instead of a return function, maybe use rather a procedure (See ‘procedure’ (from 19 Apr, 2020: Introducing procedure in preprocessor (V1.2020.7))), as:

@startuml
!unquoted procedure $app($id)
      System($id, 'label_from_app', 'description_from_app')
!endfunction

!includeurl https://raw.githubusercontent.com/RicardoNiepel/C4-PlantUML/release/1-0/C4_Container.puml
System(aa, 'aa system')
System(bb, 'bb system', 'big system')
$app(tm)
@enduml


[Click on the image to view code]

Regards,
Th.

...