Use of ## in !define macro stops macro replacement

0 votes
asked Nov 30, 2018 in Wanted features by redihokuto (140 points)

Hello,

The snippet

@startuml

participant ashly

participant blake

!define blob_arw #202020

!define interact( task, src, msg, trg )  src [task##_arw]-> trg: msg

interact( blob, ashly, HELLO, blake )

@enduml

The intention is to have

ashly [#202020]-> blake: HELLO

But it happens the parser produces 

ashly [blob_arw]-> blake: HELLO

signaling an error.

It seems to me that the macro expansion is stopped and does not go on further to replace blob_arw as it should do (since it is a macro)

I tried different tricks since I'm C programmer and deal with macros, but nor of them worked out. The usage of ## stops the expansion of that string.

Is there a way to workaround it? If not, do you think it is possible to add the feature?

Many thanks in advance

commented Nov 30, 2018 by redihokuto (140 points)
Just after writing the question I found this
http://forum.plantuml.net/4954/macro-expansion-in-two-steps-with-%23%23-does-not-work
that is reporting the same issue. I'm sorry I didn't find it before even though I searched into the database.
I confirm the workaround to swap macro definitions works for me too.

Anyhow do you think it is possible to improve the feature and make it not dependent from definition position? It is more "natural" to define things before they are used...

Thanks
commented Nov 30, 2018 by redihokuto (140 points)
Back again  :)

@startuml

participant ashly
participant blake

!define interact( task, src, msg, trg )  src [color_##task##_arw]-> trg: msg
!define color_blob_arw        #202020

interact( blob, ashly, HELLO, blake )

@enduml

Double concatenation does not work. The produced string is
"color_blob##_arw"
So it gets expanded and concatenated on the left, but not on right

And this is a workaround

!define interact(task,src,msg,trg)  src [color_arw(color_##task)]-> trg: msg
!define color_arw(x)        x##_arw
!define color_blob_arw        #202020

Do not add spaces to the nested call "color_arw(color_##task)" inside parenthesis, otherwise they get preserved.

I hope to have highlighted an area of improvement.

1 Answer

+1 vote
answered Dec 3, 2018 by plantuml (295,000 points)
selected Dec 4, 2018 by redihokuto
 
Best answer

Thanks for the feedback.

## expansion has been solved in last beta http://beta.plantuml.net/plantuml.jar

So

@startuml
participant ashly
participant blake

!define interact( task, src, msg, trg )  src [color_##task##_arw]-> trg: msg
!define color_blob_arw        #202020

interact( blob, ashly, HELLO, blake )
@enduml

should be working now.

commented Dec 4, 2018 by redihokuto (140 points)
Thanks,

just tested and concatenation works as expected.

Good job!
...