Questions regarding preprocessorV2

0 votes
asked Apr 25 in Question / help by mgrol (2,570 points)

Hi,

first of all thank you for implementing the new preprocessor. This is great. 

For testing I used a Windows 10, PlantUML version 1.201906beta1, Graphviz 2.38 and JDK 1.8.0.202

I have a couple of questions that popped up while testing:

1) !functions do not allow pretty print with identation? It that a wanted feature? Meaning this is not possible:

!function $test1($name="blub")
    a --> b : $name
!endfunction

2)  While including a file that does not contain a @startuml/@enduml section works, I get a syntax error when they do.

* include.iuml

!function $test1($name="foo")
a --> b : $name
!endfunction
* main.puml
@startuml
!include include.iuml
$test1("bar")
$test1()
@enduml


3) already0047 might occur when using !include within function
4) Currently the builtin functions %dirpath()  and %filename() do not work for me. They appear to return empty values on an windows 10 pc.
5) %file_exists() reuqired an absolute path. Will this change or not. Is it planned that one can nest builtin functions %file_exist(%dirname() + "file")
6) !definelong and !functions cannot be mixed? I'd like to gradually migrate my plantuml files. Or is this an issue that might be connected to 2)


BR,
Michael

1 Answer

0 votes
answered Apr 25 by plantuml (198,780 points)

Thanks for your tests.
We've made a new beta with few fixes ( http://beta.plantuml.net/plantuml.jar )

> 1) !functions do not allow pretty print with identation?
>
It should work with indentation. Did you use tabulations or spaces ?

> 2)  While including a file that does not contain a @startuml/@enduml section works, I get a syntax error when they do.
>
Ok, fixed in last beta

> 3) already0047 might occur when using !include within function
>
Ok, fixed in last beta : we now accept function redefinition (which probably occurs when using !include )

> 4) Currently the builtin functions %dirpath()  and %filename() do not work for me. They appear to return empty values on an windows 10 pc.
>
This is strange. Did you use the command line ? Or from some other tools ?
The following example is working for us:

@startuml
title %dirpath() %filename()
!include include.iuml
$test1("bar")
$test1()
@enduml


> 5) %file_exists() required an absolute path. Will this change or not. Is it planned that one can nest builtin functions %file_exist(%dirname() + "file")
>
Right now we sick on absolute path.
You can nest functions (buitlin or return function) and variables.
And you can use !assert in that case:

!function fileSeparator() return '/'
!$filename = "foo.txt"
!assert %file_exists(%dirpath() + fileSeparator() + $filename) : %dirpath() + fileSeparator() + $filename + " does not exist"


6) !definelong and !functions cannot be mixed? I'd like to gradually migrate my plantuml files.
Yes, you should be able to mix !definelong and !function
Our tests are not complete, so there might be some issues. Do not hesitate to post :-)

Thanks

commented Apr 26 by mgrol (2,570 points)
Hi,

thank you for your answers.

>> 1) !functions do not allow pretty print with identation?
>It should work with indentation. Did you use tabulations or spaces ?
I used spaces, but the same appears with tabs. I see the problem, when defining a function I idented the first line after the function. This causes an error
!function $inc($value, $step=1)
    !if ($step == 0)
        !return $value
    !endif
    !return $value + $step
!endfunction
And I usually get a "</w> Syntax error".

2) The bugfix for include errors on @startuml/@enduml is confirmed. It works now.

3) Thank you. You might consider a directive !final function that exacly disallows the overriding for some functions. As for now, I am happy with the bugfix. And yes, the error was caused by the multi-includes.

4) Yes, I currently use a plugin in Intellij. By using the jar stand-alone it works. This is then an issue from the plugin.

5) Thank you.

6) I will continue to test.

7) (New) With the new beta I experience a syntax error when using !undef <something>.

Thank you for your good work.

BR,
Michael
commented Apr 26 by plantuml (198,780 points)
> I see the problem, when defining a function [...]
>
Ok, understood.
This should be solved in last beta http://beta.plantuml.net/plantuml.jar

> You might consider a directive !final function that exacly disallows the overriding for some functions
>
Good idea! This is also implemented in last beta

> This is then an issue from the plugin.
>
Well, not completely, we have to explain to the plugin owner how to make it work.
I guess that the plugin uses a SourceStringReader instance.
There are some constructor of SourceStringReader that takes a Defines as argument.

You have to create a Defines using the static method "Defines.createWithFileName(someFile)"
(code at https://github.com/plantuml/plantuml/blob/master/src/net/sourceforge/plantuml/preproc/Defines.java#L97 )
This will define the variable filedate, dirpath and filename


> With the new beta I experience a syntax error when using !undef <something>.
>
Ok, fixed with last beta.

Please go on with your tests :-)
commented Apr 29 by mgrol (2,570 points)
Hi,

thank you.

7)
>> With the new beta I experience a syntax error when using !undef <something>.
> Ok, fixed with last beta.
Confirmed.


>> You might consider a directive !final function that exacly disallows the overriding for some functions
> Good idea! This is also implemented in last beta
Thank you. It works.

As to 6)
This was obviously my mistake. I managed to mix both approaches

As for the plugin I will have to check. It is the intellij Plugin from eugenesteinberg.

I will continue to test over the next couple of days.
commented Apr 29 by mgrol (2,570 points)
Next point

!includes: From which point are !includes handled?
Given three files in folders:
- a/a.puml, a/b/b.puml, c.puml
- a.puml contains !include b/b.puml
- b.puml contains !include ../../c.puml
- c.puml contains e.g. component "C" as c

This will lead to an error "cannot include", whereas !include ../c.puml does the job.

That means that after the file b is included the search path for the include is relative to the file that included the first file. Meaning relative to a.puml and not as I would think relative to b.puml
commented Apr 29 by mgrol (2,570 points)
There is  an issue when initializing a variable and using tabs
!$a = 1 works but !$a<tab>= 1 does not. Error a001 will be returned
commented Apr 29 by plantuml (198,780 points)
> !includes: From which point are !includes handled?
[...]
> There is  an issue when initializing a variable and using tabs

Thanks!
Both issues should be fixed in last beta ( http://beta.plantuml.net/plantuml.jar )
commented Apr 30 by mgrol (2,570 points)
>> !includes: From which point are !includes handled?
[...]
bugfix confirmed

>> There is  an issue when initializing a variable and using tabs
bugfix confirmed
commented Apr 30 by mgrol (2,570 points)
With beta10, this example will cause a syntax error
@startuml
$ifdef $j
Alice -> Bob : The variable j is defined and its value is $j
$else
Alice -> Bob : I don't know any j variable
$endif
As well as you would define $j by "!$j = true"
commented Apr 30 by plantuml (198,780 points)
Thanks! This is fixed in beta11 http://beta.plantuml.net/plantuml.jar

This beta contains some new builtin functions and new features documented here http://wiki.plantuml.net/site/preprocessing-v2
For example, you may use %variable_exists() instead of !ifdef

With this last beta11, you can have :
@startuml
!preprocessorV2
!ifdef $j
Alice -> Bob : The variable j is defined and its value is $j
!else
Alice -> Bob : I don't know any $j variable
!endif

!if %variable_exists("$j")
Alice -> Bob : The variable j is defined and its value is $j
!else
Alice -> Bob : I don't know any $j variable
!endif

@enduml
commented Apr 30 by mgrol (2,570 points)
Thank you.

Both solutions work and the bugifx is confirmed.
Thank you also for the update of the documentation. My next question was solved there as well the booleans $true/$false were changed to %true() %false()
...