preprocessorV2: quotes in function arguments

0 votes
asked May 3, 2019 in Question / help by StefanDensow (280 points)
Hi,

I use preprocessor functions, (currently) all of which take string arguments. preprocessorV2 now requires quotes around strings, which I find too verbose for my use case. So I use !unquoted and it works as expected:

!unquoted function $CALL_METHOD($FROM_CLASS, $TO_CLASS, $FUNC_NAME, $ARG = "", $RETURN_LABEL = "")
    $FROM_CLASS -> $TO_CLASS: $FUNC_NAME($ARG)
    activate $TO_CLASS
        !include $TO_CLASS.iuml!$FUNC_NAME
    $FROM_CLASS <-- $TO_CLASS: $RETURN_LABEL
    deactivate $TO_CLASS
!endfunction

Can be used as: $CALL_METHOD(Concierge, Concierge, doThis, without //quotes//)

Even spaces in arguments are no issue. That's all great!

However, why are quotes required by default?

And what issues may arise when using !unquoted? The docs at http://wiki.plantuml.net/site/preprocessing-v2 describe but don't explain..

Thanks!

1 Answer

+1 vote
answered May 6, 2019 by plantuml (295,760 points)
selected May 7, 2019 by StefanDensow
 
Best answer

However, why are quotes required by default?

The need for quotes comes from the fact that now the preprocessor V2 accepts complex expressions in argument.

So if you have :

Alice -> Bob : hello $bold(2+4)

It's not clear whether you want to print 6 or the string "2+4". The vast majority of programming language will add 2 to 4 and print 6 in that case.

So you need to use quotes, if you want to exactly print 2+4 :

Alice -> Bob : hello $bold("2+4")

We agree that it's a change from actual preprocessor, however this sounds more consistant with other programming languages.

To mitigate the change, we introduce the unquoted keyword because we realize that this may be handy in some situation to avoid quotes. But by default, we stick now to usual standards.

Does it sound better now ?

commented May 7, 2019 by StefanDensow (280 points)
Yep, thanks for the explanation.

Is my understanding of !unquoted correct that it acts just as if all arguments were given in quotes? I.e. if I need at least one argument interpreted as integer, I have to remove !unquoted and use quotes with the remaining string arguments?
If so, I'm happy with that. You picked a reasonable default and provided a reasonable way to switch it. All good :-)
commented May 7, 2019 by plantuml (295,760 points)
> if I need at least one argument interpreted as integer, I have to remove !unquoted and use quotes with the remaining string arguments?
>
Yes, exactly.

See for example http://www.plantuml.com/plantuml/uml/bOwn3e9038RtUufoOO200xWv6FGXtE4evX9eiTSElhqOIKpSNF_l-z9sINjHMsQNhOAhSC2KM6wjoumUneeZJ4P18nFa4tEH9vL8znhoI5g2e9eGx6lbeQSHV5MyQTMKBllMeotByz_UNUOO40vdkF80fyyF_H1gQDfZ-Klt6tuJ_6vqIDiulm00
commented May 7, 2019 by plantuml (295,760 points)
BTW, if you need, we could also implement some %intval() function that would convert a String to an integer. This way, you could still use !unquoted and convert some of the String argument to int. Just tell us if it would be useful
commented May 9, 2019 by StefanDensow (280 points)
Thanks for the clarification.

The %intval() proposal sounds useful, especially in conjunction with %substr() extraction.
...