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.

Substituting variable using !define

0 votes
When haveing the following inpout file:

@startuml
!define SHOW_TYPE(x) my_x
class ArrayList
ArrayList : SHOW_TYPE(my_type) size()
@enduml

 

The result is that in the resulting image in the second part just "my_x" is shown, so missing "size()"

In case of:

@startuml
!define SHOW_TYPE(x) x
class ArrayList
ArrayList : SHOW_TYPE(my_type) size()
@enduml

The result is that the resulting image shows my_type) size(

 

Also, as far as I can see, in case of !define X(y) and using !ifdef X this results in "False"

 

(It is known that the preprocessing possibilities are limited)
asked Sep 10, 2014 in Closed bug by albert (400 points)
recategorized Sep 13, 2014 by albert

2 Answers

0 votes

There is a bug in the current version, which is corrected in the following beta:

https://dl.dropboxusercontent.com/u/13064071/plantuml.jar

However, there is still an unresolved issue. The underscore is considered as a letter (see http://www.regular-expressions.info/wordboundaries.html )

So:

!define SHOW_TYPE(x) my_x

won't work because "mu_x" is seen a single word, just like "myx"

In compairison,

!define SHOW_TYPE(x) my-x

will work, because x is here alone.
Is it a real issue for you ?
answered Sep 11, 2014 by plantuml (124,290 points)
The first 2 problems (note I corrected the code of the second example, to be correct with the error message).

The define versus ifdef problem still exists, see example in this comment.

@startuml
!define SHOW_TYPE(x) my-x
class ArrayList
!ifdef SHOW_TYPE
ArrayList : SHOW_TYPE(my_type) size()
!else
ArrayList : SHOW_TYPE not set size()
!endif
@enduml

The noted problem regarding my_x as been seen as a whole word is not a problem at all for me. The first example was more to show the missing size().
The ifdef problem should be solved with the last uploaded beta:
https://dl.dropboxusercontent.com/u/13064071/plantuml.jar

Many thanks for your tests & feedback, it really help us to improve the preprocessor!

While using the preprocessor, if you have ideas of improvements, do not hesitate to post suggestions here.
Thanks, tested it with the latest file (retrieved 13 Sep 2014) and it works.

One thing is a bit confusing, I downloaded the latest, as I did also yesterday (where the problem still occurred), they had the same name and also the same version information (PlantUML version 8005beta (Sat Aug 23 18:23:53 CEST 2014)) but the size was a little bit different. Maybe there is a way to have the build date in the version string / have some way of showing which versions are available.
Good idea : we have started to add numbers to beta. The latest is now 8005beta2 (because we have fixed yet another issue http://plantuml.sourceforge.net/qa/?qa=2444/eps-output-format-with-salt )
Thank, indeed better identification, but the date is still a bit old:
PlantUML version 8005beta2 (Sat Aug 23 18:23:53 CEST 2014)
0 votes
To work around the _ counting a letter replace it with a unicode "LOW LINE" character, like this:

!define SHOW_TYPE(x) my<U+005F>x

Now SHOW_TYPE(fred) will become: my_fred
answered Apr 13 by Terry (150 points)
Support This Project Offer 250 Mo! Follow PlantUML on Twitter
...