summaryrefslogtreecommitdiff
path: root/librelogo/source
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2013-10-25 08:30:30 +0200
committerAndras Timar <andras.timar@collabora.com>2013-10-25 16:49:42 +0200
commit4d576a2cbc6cdadea578ba3c2f408ba6676bf101 (patch)
tree62d049ec867b6d3bf93eef3e39286e513ef52743 /librelogo/source
parent929dc54a1bb034d787a5a90d7c2d9d603ecfbfa3 (diff)
librelogo: fix division with measurements
Change-Id: I2204002533bbb3e7c801b3228b0310a42b19a882 (cherry picked from commit 7744c4a0016be338c6c14b14f620d8af7d76111e)
Diffstat (limited to 'librelogo/source')
-rw-r--r--librelogo/source/LibreLogo/LibreLogo.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/librelogo/source/LibreLogo/LibreLogo.py b/librelogo/source/LibreLogo/LibreLogo.py
index b524a8cf58da..5076c7ca68ea 100644
--- a/librelogo/source/LibreLogo/LibreLogo.py
+++ b/librelogo/source/LibreLogo/LibreLogo.py
@@ -1359,7 +1359,7 @@ def __loadlang__(lang, a):
[r"(?<=\n)__repeat__([^\n]*\w[^\n]*):(?=\n)", "for %s in range(1, 1+int(\\1)):" % repcount], # repeat block
[r"(?<=\d)[%s](?=\d)" % a['DECIMAL'], "."], # decimal sign
[r"(?<!/)/(?!/)", "*1.0/"], # fix division: /1 -> /1.0, but not with //
- [r"\b([0-9]+([,.][0-9]+)?)(%s)\b" % a['HOUR'], "\\1*30"], # 12h = 12*30°
+ [r"\b([0-9]+([,.][0-9]+)?)(%s)\b" % a['HOUR'], lambda r: str(float(r.group(1).replace(",", "."))*30)], # 12h = 12*30°
[r"(?<=\d)(%s)" % a['DEG'], ""], # 1° -> 1
[r"(?<!:)\b(?:__def__)[ \t]+(\w+)\b[ \t]*([:]?\w[^\n]*)", "\ndef \\1(\\2):\n["],
[r"(?<!:)\b(?:__def__)\s+(\w+)", "\ndef \\1():\n["],
@@ -1431,9 +1431,9 @@ def __loadlang__(lang, a):
[r"(?<!:)\b(?:%s)\b" % a['PRINT'], "\n)Print("],
[r"(?<!:)\b(?:%s)\b" % a['TURNLEFT'], "\n)turnleft("],
[r"\b([0-9]+([,.][0-9]+)?)(%s)\b" % a['PT'], "\\1"],
- [r"\b([0-9]+([,.][0-9]+)?)(%s)(?!\w)" % a['INCH'], "\\1*72"],
- [r"\b([0-9]+([,.][0-9]+)?)(%s)\b" % a['MM'], "\\1*%s" % __MM_TO_PT__],
- [r"\b([0-9]+([,.][0-9]+)?)(%s)\b" % a['CM'], "\\1*%s*10" % __MM_TO_PT__],
+ [r"\b([0-9]+([,.][0-9]+)?)(%s)(?!\w)" % a['INCH'], lambda r: str(float(r.group(1).replace(",", "."))*72)],
+ [r"\b([0-9]+([,.][0-9]+)?)(%s)\b" % a['MM'], lambda r: str(float(r.group(1).replace(",", "."))*__MM_TO_PT__)],
+ [r"\b([0-9]+([,.][0-9]+)?)(%s)\b" % a['CM'], lambda r: str(float(r.group(1).replace(",", "."))*__MM_TO_PT__*10)],
[r"\b(__(?:int|float|string)__len|round|abs|sin|cos|sqrt|set|list|tuple|sorted)\b ((?:\w|\d+([,.]\d+)?|0[xX][0-9a-fA-F]+|[-+*/]| )+)\)" , "\\1(\\2))" ], # fix parsing: (1 + sqrt x) -> (1 + sqrt(x))
[r"(?<=[-*/=+,]) ?\n\)(\w+)\(", "\\1()"], # read attributes, eg. x = fillcolor
[r"(?<=return) ?\n\)(\w+)\(", "\\1()"], # return + user function