More than one arg in macro?

0 votes
asked Jan 17, 2014 in Wanted features by rmric (2,140 points)

Hi,

Is it possible for a preprocessing macro to take more than one argument?

@startuml

!define module(x,y) component "Module: x" as y <<module>>
module(the first letters,ABC)
module(the last letters,XYZ)
@enduml

Another wish: leveraging the !include for style sheet definition through sinkparams/marcros, I would like to share the same .iuml file for various diagrams (sequence, component, ..). Since some forms differs, I would need to do some !ifdef'ing. Could PlantUML automatically !define the type of diagram (__SEQUENCE_DIAGRAM__, __COMPONENT_DIAGRAM__, ..) while preprocessing ?  Rem: the define cannot be done on the command line, because it has to work also for different diagrams in doxygen source file.

Many thanks for the great features in PlantUML

1 Answer

0 votes
answered Jan 18, 2014 by plantuml (294,960 points)

Good idea! Your example is working with the following beta https://dl.dropboxusercontent.com/u/13064071/plantuml.jar

As usually, very few tests have been done, so feedback is welcome.

About predefining the type of diagram while preprocessing, this is unfortunalty not possible. First because preprocessing occurs before syntax analyzing. Moreover, this could lead to paradoxal result:

!ifdef __SEQUENCE_DIAGRAM__
!define foo(x) class x
!else
!define foo(x) participant x
!endif
foo(Bob)

If the following example is a __SEQUENCE_DIAGRAM__, then it's a class diagram...

What about normalizing skinparam forms (we are working on this right now), to solve your needs?

Just tell us which issue(s) you are dealing with.

Thanks,

commented Jan 21, 2014 by rmric (2,140 points)
edited Jan 21, 2014 by rmric
As usual, very quick answer, thanks!
The multi-argument macro is working fine, and it's even possible to do polymorphism:

@startuml
!define module(x,y) component "Module: x" as y <<module>>
!define module(x) component "Module: x" <<module>>
module(the first letters,ABC)
module(the last letters,XYZ)
module(GHI)
@enduml

However, a macro cannot be defined by another macro. But that's OK for me since I don't have such a need.

!define module_favorite(x) module(x) #Red
module_favorite(Bridge)


About predefining the type of diagram, I understand it's hard to resolve this chicken'n'egg problem, unless doing multi-pass parsing without preproc first.

One workaround is to explicitly define the type of diagram beforehand, but it's cumbersome:

!define __SEQUENCE_DIAGRAM__
!include my_stylesheet.iuml
module(blah)

What I would like to do is to have the same macro name to declare an element in different diagram types (sequence, component, ..) , such that the aspect is the most uniform. Needless to say, the stereotyped skinparams (read stylesheets) will then have a role to play.

!ifdef __SEQUENCE_DIAGRAM__
!define module(x,y) participant "Module: x" as y <<module>>
skinparam participantBackgroundColor<<module>> LightBlue
!else
!define module(x,y) component x "Module: x" as y <<module>>
skinparam componentBackgroundColor<<module>> LightBlue
!endif

I'm not sure to see exactly what you're meaning by normalizing the skinparam forms.

Regards

EDIT: macro defined by another macro
...