Welcome to PlantUML Q&A, where you can ask questions and receive answers from other members of the community.

You can also submit new features request and vote for them.

Define a multi line macro

+2 votes

Hi community ;)

 

I want to define a multi lines macro so that it could replace:

@startuml
Alice -> Bob: Authentication Request
Bob --> Alice: Authentication Response
@enduml

by for example:

@startuml
AUTHENT
@enduml

That way, I 've tried  to define multi line macro like this:

!define AUTHENT Alice -> Bob: Authentication Request \
Bob --> Alice: Authentication Response

 

But it is not working :S

Any Idea/help?

 

Best regards,

David

 

 

 

asked Jan 21, 2014 by davidP (410 points)

2 Answers

+2 votes

Good idea!

With the following beta: https://dl.dropboxusercontent.com/u/13064071/plantuml.jar

You can have:

@startuml
!define AUTHENT Alice -> Bob: Authentication Request \
on a single line

!define ENDING Alice -> Bob: This is\
 the end\
 my friend\
 bye!

AUTHENT
Alice -> Bob : this is \
on a single line
ENDING
@enduml

Is this what you are expecting ?

answered Jan 22, 2014 by plantuml (125,190 points)

Hello,

Thanks for your prompt reply.

It is a good proposal (a nice new feature) but I 'm not sure it was really my expectation ;)

My idea was to have (for example) two messages define by one single CONSTANT.
When preprocessed, the "multi line" CONSTANT will be replaced by severals lines/commands.

for example:

@startuml
!define AUTHENT { Alice -> Bob: Authentication Request \
Bob --> Alice: Authentication Response }

AUTHENT
@enduml

would be replaced after pre-processing by:


@startuml
Alice -> Bob: Authentication Request 
Bob --> Alice: Authentication Response
@enduml

Do you it is something feasible/coherent?

BTW, today I used an external file for that:
Like this

externalfile.txt:

Alice -> Bob: Authentication Request 
Bob --> Alice: Authentication Response

and in main file:

@startuml
!include externalfile.txt:
@enduml

 

 

BR,

David

 

 

 

 


 

0 votes

In the last beta : https://dl.dropboxusercontent.com/u/13064071/plantuml.jar

You can define define on several lines, using !definelong and !enddefinelong

@startuml
!define DOUBLE(x) x x
!definelong AUTHEN(x,y)
x -> y : DOUBLE(hello)
y -> x : ok
!enddefinelong
AUTHEN(Bob,Alice)
@enduml

Does it helps ? We do not like the !enddefinelong keyword because it's quite long. Any suggestion?

Note also that a define can now use another define.

answered Jan 23, 2014 by plantuml (125,190 points)
Yes, it helps. Thanks ;)

About the  !enddefinelong keyword, why not use the syntax of C language pre-processing: Use the semicolons and the "\" to indicate a line continuation.
http://www.geeksforgeeks.org/multiline-macros-in-c/

So that I could write
@startuml
!define DOUBLE(x) x x
!define AUTHEN(x,y) { \
x -> y : DOUBLE(hello) \
y -> x : ok }
AUTHEN(Bob,Alice)
@enduml
Support This Project Offer 250 Mo! Follow PlantUML on Twitter
...