librelogo/source/LibreLogo/LibreLogo.py |   10 ++++++++--
 sw/qa/uitest/librelogo/compile.py       |    3 +++
 2 files changed, 11 insertions(+), 2 deletions(-)

New commits:
commit 37d8678d7266fd517953d3db39e30ff8775ade7f
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Sun Dec 4 20:33:36 2022 +0100
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Mon Dec 5 16:16:09 2022 +0000

    LibreLogo: fix parsing argument of default Logo commands
    
    Functions didn't work in arguments of several default
    Logo commands (mostly turtle moving and setting).
    A simple example, which resulted an error message:
    
    FORWARD RANDOM 100
    
    Regression from commit 740b99783b5480fcd1e5fce7c1beb5967d015041
    "tdf#120413 LibreLogo: handle complex Logo expressions".
    
    Change-Id: Icb4aece1a5b0343384ce179c27f170eef7d8938c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143642
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git a/librelogo/source/LibreLogo/LibreLogo.py 
b/librelogo/source/LibreLogo/LibreLogo.py
index 717df1a968a1..5f0c2261f614 100644
--- a/librelogo/source/LibreLogo/LibreLogo.py
+++ b/librelogo/source/LibreLogo/LibreLogo.py
@@ -2211,8 +2211,14 @@ def __compil__(s):
             # atom: other tokens (variable names, numbers and function names)
             atom = {key: value for (key, value) in [j.span() for j in 
list(atoms.finditer(i))]}
             par = {"pos": 0, "out": "", "sub": sub, "op": op, "atom": atom, 
"names": names}
-            __l2p__(i, par, False, False)
-            i = par["out"]
+            if i.startswith(')') and '(' in i:
+                # replace ")forward(" etc. with spaces temporarily
+                len_name = i.index('(') + 1
+                __l2p__(' ' * len_name + i[len_name:], par, False, False)
+                i = i[:len_name] + par["out"].lstrip()
+            else:
+                __l2p__(i, par, False, False)
+                i = par["out"]
         # starting program block
         if i[0:1] == '[':
             i = i[1:]
diff --git a/sw/qa/uitest/librelogo/compile.py 
b/sw/qa/uitest/librelogo/compile.py
index 3cc1198cc1d7..bf4668e8e332 100644
--- a/sw/qa/uitest/librelogo/compile.py
+++ b/sw/qa/uitest/librelogo/compile.py
@@ -111,6 +111,9 @@ class LibreLogoCompileTest(UITestCase):
                 ("a=RANDOM 40 + 120", "a=Random(40 + 120)"),
                 ("a=RANDOM(40) + 120", "a=Random(40) + 120"),
                 ("a=RANDOM [1, 2, 3]", "a=Random([1, 2, 3])"),
+                ("PRINT RANDOM 40", "Print(Random(40))"),
+                ("FORWARD RANDOM 40", "forward(Random(40))"),
+                ("FORWARD 10 + RANDOM 40 + RANDOM 100", "forward(10 + 
Random(40 + Random(100)))"),
                 ("a=[sin 90 + cos 15, cos 100 * x, sqrt 25 * 25]", "a=[sin(90 
+ cos(15)), cos(100 * x), sqrt(25 * 25)]"),
                 ("a=[sin 90 + cos 15, cos 100 * x, sqrt 25 * 25]", "a=[sin(90 
+ cos(15)), cos(100 * x), sqrt(25 * 25)]"),
                 ("a=[sin(90) + cos 15, cos(100) * x, sqrt(25) * 25]", 
"a=[sin(90) + cos(15), cos(100) * x, sqrt(25) * 25]"),

Reply via email to