new "!Includestring $var" command which loads the $var content like a file

0 votes
asked Jan 29, 2023 in Wanted features by kirchsth (4,980 points)
edited Jan 29, 2023 by kirchsth

I want to simplify the definition of (customer specific) procedures/functions in the C4 model.

And my idea was to write a function which defines the new functions/procedures into a string and then include the string like a file. My first idea (without the !includestring) was that I write it directly into the file but this produces a syntax error like below

@startuml
!unquoted function Call($from, $to, $text = "calls")
!$sq="'"
!$dq='"'
!$def = '[' + $dq + $from + $dq +']->[' +$dq + $to + $dq + '] :' + $dq + $text + $dq
!return $def
!endfunction

Call(a 1, b 1)

!unquoted function $defineCall2($newDefault)
  !$sq="'"
  !$dq='"'
  !$def = '!unquoted procedure Call2($from, $to, $text = ' + $dq + $newDefault + $dq + ')' + %newline()
  !$def = $def + '[' + $dq + '$from' + $dq +']->[' +$dq + '$to' + $dq + '] :' + $dq + '$text' + $dq + %newline()
  !$def = $def + '!endprocedure' + %newline()
  !return $def
!endfunction
$defineCall2("is called via message")

' with following include call, could it work
' !includestring $defineCall2("is called via message")

Call2(c 1, d 1)
@enduml


Atm. I could only create via a `-preproc` command an intermediate file and in a second call create the final diagram.

@startuml

["a 1"]->["b 1"] :"calls"

!unquoted procedure Call2($from, $to, $text = "is called via message")
["$from"]->["$to"] :"$text"
!endprocedure


Call2(c 1, d 1)
@enduml

With `!includestring $defineCall2("is called via message")` dynamic macros would be possible.

Thank you and best regards
Helmut

commented Feb 1, 2023 by The-Lu (64,760 points)
commented Feb 3, 2023 by kirchsth (4,980 points)

Hello The-Lu,

from the problem perspective I agree, but I think my solution approach is much simpler.
I think it needs only a local replace statement instead of a recursive preprocessor handling, ...
because if I use a normal !include the current implementation tries already to load the calculated string


And if the new implementation would only replace the `!includestring $defineCall2(...)` with the corresponding return value of the function the implementation could support dynamic created procedures too.

BR Helmut

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:

[Antispam2 Feature: please please wait 1 or 2 minutes (this message will disappear) before pressing the button otherwise it will fail](--------)
To avoid this verification in future, please log in or register.
...