New preprocessor: returning elements from functions

+1 vote
asked Sep 2 in Question / help by Erik

Hi

I am trying to migrate my current macros for the new preprocessor and I'm following the migration guide here: http://plantuml.com/preprocessing.

It says there that 

!define should be replaced by return function 

I used to be able to nest elements inside of elements created by macros:

!define boundary_def(label) rectangle label <<boundary_def>>

boundary_def("define") {
    actor jim
}

However, I am not sure how I should do this with a function as the following:

!function $boundary_fun($e_label) return rectangle $e_label <<boundary_fun>>

$boundary_fun("function")
{
    actor tim
}

gives me a syntax error:

Unknown variable rectangle

1 Answer

0 votes
answered Sep 2 by plantuml (202,540 points)

You have two working options :

@startuml
!function $boundary_fun($e_label) return "rectangle "+$e_label+" <<boundary_fun>>"

$boundary_fun("foo") {
    actor tim
}
@enduml

or

@startuml
!function $boundary_fun($e_label)
rectangle $e_label <<boundary_fun>> {
!endfunction

$boundary_fun("foo")
    actor tim
}
@enduml

The following one is not working, and it looks like a bug.
We are going to investigate :

@startuml
!function $boundary_fun($e_label)
rectangle $e_label <<boundary_fun>>
!endfunction

$boundary_fun("foo")
{
    actor tim
}
@enduml
commented Sep 2 by Erik
Thank you for the fast response.

Your first suggestion seems quite reasonable, the second one is a bit hacky though :)
commented 5 days ago by rd27 (420 points)

I am running into the same or similar bug you mention in the third case. From what I can tell putting the curly bracket on the next line always give a "Syntax error", even when no preprocessing is involved:

@startuml
node a 
{
  rectangle b
}
@enduml

On a related note, like the original question. If I try to put a curly bracket on the same line as a new macro I get the error "No package or namespace defined". So second node below fails.

@startuml

!function $BIN2($sn)
node $sn
!endfunction

$BIN2("a2")

$BIN2("b2") {
  rectangle c2
}

@enduml


commented 3 days ago by plantuml (202,540 points)

Thanks for the feedback.

With last beta http://beta.plantuml.net/plantuml.jar your last example is now working :

@startuml
!function $BIN2($sn)
node $sn
!endfunction

$BIN2("a2")

$BIN2("b2") {
  rectangle c2
}
@enduml

Tell us if you find other issues!

...