Substituting variable using !define

0 votes
asked Sep 10, 2014 in Closed bug by albert (3,520 points)
recategorized Sep 13, 2014 by albert
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)

2 Answers

0 votes
answered Sep 11, 2014 by plantuml (294,960 points)
selected Jun 13, 2018 by albert
 
Best answer

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 ?
commented Sep 12, 2014 by albert (3,520 points)
edited Sep 12, 2014 by albert
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().
commented Sep 12, 2014 by plantuml (294,960 points)
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.
commented Sep 13, 2014 by albert (3,520 points)
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.
commented Sep 13, 2014 by plantuml (294,960 points)
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 )
commented Sep 14, 2014 by albert (3,520 points)
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
answered Apr 13, 2017 by Terry (140 points)
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
...