Define a multi line macro

+2 votes
asked Jan 21, 2014 in To be sorted by davidP (300 points)

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

 

 

 

2 Answers

+2 votes
answered Jan 22, 2014 by plantuml (294,960 points)

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 ?

commented Jan 23, 2014 by davidP (300 points)
moved Jan 23, 2014 by davidP

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
answered Jan 23, 2014 by plantuml (294,960 points)

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.

commented Jan 24, 2014 by davidP (300 points)
edited Jan 24, 2014 by davidP
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
...