string concatenation/function evaluation in includes

0 votes
asked May 7, 2021 in Question / help by anonymous

I guess this is maybe a constraint of the preprocessor, but here's a quick example the illustrates the problem:

@startuml
!$ICONPATH=%getenv("HOME")+"/misc/plantuml-icon-font-sprites"

' doesn't work:
'!include %getenv("HOME")+"/misc/plantuml-icon-font-sprites/common.puml"

' doesn't work:
'!include $ICONPATH+"/common.puml"

' works fine:
!$COMMONPATH=$ICONPATH+"/common.puml"
!include $COMMONPATH

' also works fine!?
!function $fainclude ($p)
!$PPATH = $ICONPATH+$p
!return $PPATH
!endfunction
!include $fainclude("/common.puml")

usecase ($ICONPATH)
'usecase ($COMMONPATH)
usecase ($fainclude("/common.puml"))
@enduml

As you can see, you can't evaluate a built in function in an !include line, nor can you do string concatenation (which, I guess, is just another built in function...). But: !include can evaluate user defined functions. Or am I missing something here? What's the best way to achieve what I want, which is to include a bunch of files from the font-awesome library. I don't want to have to change the executable, I'd rather have the inclusions happen at the top of the file...

commented May 7, 2021 by anonymous
I realise now that I am actually trying to replicate functionality that's now in the standard library, but, I think the general question is still interesting.

1 Answer

0 votes
answered May 7, 2021 by plantuml (265,020 points)

Yes for sure,  the general question is still interesting.

This is a constraint of the preprocessor, and indeed you cannot do string concatenation in !include.

We have tried to bound this limitation:

  • You can evaluate user defined function (which is a possible workaround in your case)
  • You can also define variable line like in this example (which is an even better workaround)
Even if it's not perfect, we think it's flexible enough for the majority of users.
If you are curious, we could detail why concatenation is not possible, but this would bring a long explanation...
commented May 7, 2021 by anonymous
Ah great. This is helpful thanks. It's reassuring that it wasn't working because it was a limitation of the preprocessor, ratther than because I was doing something silly!
...