Preprocessor vlookup macro

+1 vote
asked Apr 5, 2020 in Question / help by gobravedave (200 points)

I am loving PlantUML and have many lines of script.. As the number of lines of script grows, the overall effort to keep the diagrams consistent and standard gets difficult.

To assist, I am attempting to write a simple macro which works along the lines of a excel vlookup where you pass in a search string, a file name of what is to be searched and an offset value to be returned.

However i am struggling on my first attempt with a parsing error. I am hoping some fresh eyes can help.. or even better if someone in the plantuml community has already done something along these lines.  

thank you,

David.

@startuml vlookup test

!preprocessorV2

!unquoted function $vlookup( $id, $range, $offset)

   !log vlookup on $id

   '!log vlookup on %get_variable_value("$id")

   !$row1 = "cm|customer master|manages customers"

   !$row2 = "tm|transaction manager|manages transactions"

   !$row3 = "am|account manager|manages accounts"

    '%set_variable_value("$row1", "cm|customer master|manages customers" )

    '%set_variable_value("$row2", "tm|transaction manager|manages transactions" )

    '%set_variable_value("$row3", "am|account master|manages accounts" )

    !if ($id == "cm")

      '!return %get_variable_value("$row1")

      !return $row1

    !endif

    !if ($id == "tm")  

      '!return %get_variable_value("$row2")

      !return $row2

    !endif

    !if ($id == "am")  

      '!return %get_variable_value("$row3")

       !return $row3

   !else

        !return "error"

    !endif

 !endfunction

!$note = $vlookup("cm", "system.iuml", 1)

component comp1 [

$note

]

@enduml

1 Answer

+2 votes
answered Apr 5, 2020 by plantuml (294,960 points)
commented Apr 6, 2020 by albert (3,520 points)

The example you show in this answer does work but differs from the original in the sens that te line

!preprocessorV2

is missing.

Should !preprocessorV2 not be used anymore? and what should be used in case a user wants to use the old preprocessor?

commented Apr 6, 2020 by plantuml (294,960 points)

For recent versions of PlantUML, this !preprocessorV2 line is not needed anymore. My guess is that David is using an outdated version.

The !preprocessorV2 directive was used by previous versions when the new preprocessor was under testing. It allowed at that time users to switch between the two preprocessors.

Now, it is simply ignored: the old preprocessor code has been removed (since May 2019).

There is no way for a user to use the old preprocessor. Ascending compatibility should be working now, possibly with very minor changes in few older diagrams.

If you find issues, please tell us !

commented Apr 6, 2020 by gobravedave (200 points)

thank you.. I double checked the version of plantuml and from VS Code usig jebbs plantuml extension, Confluence plugin.. They were all different error messges.. being empty description, syntax error. With/without the preprocessorV2 setting made no difference.

I tried using my script via the plantuml demo server and got a parsing error.

I copied your version from the supplied link and tried in VS Code.... and it worked.. smiley

so now I am happy and sad all at once.

commented Apr 6, 2020 by plantuml (294,960 points)

The only is the extra empty line inside the if block, just before the return.

Thanks Albert : I think that you have find the real issue !

It was easy to fix, so we've just publish a new beta http://beta.plantuml.net/plantuml.jar that fix this.

And we have updated the online server (Note that there might be some caching issue with already generated diagrams).

Thanks again !

so now I am happy and sad all at once.

Don't be sad :-)

I think Albert has found the real issue, and we have just published yet another correction.

I am sorry that you have lost so many time on this, but I am happy that we finally fix it :-)

commented Apr 6, 2020 by gobravedave (200 points)
thank you both very much for your help.. I guess I can continue to code locally and test using your test server. I am keen to get the %get, %set and %is variable functions working to support the recursive search of my range.
commented Apr 7, 2020 by gobravedave (200 points)
commented Apr 7, 2020 by albert (3,520 points)
@plantuml You just beat me when I was analysing the problem.

Am I corect that the problem lies in the "1" of "row1"
commented Apr 7, 2020 by gobravedave (200 points)
thanks again.. the numeric variable name, assuming @albert is correct, is going to be important for the script as I introduce the looping thru each of the rows to find the matching $id..
commented Apr 7, 2020 by albert (3,520 points)
As far as I can see on the online server the version wit the numeric value is working.
...