summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2013-10-25 08:30:30 +0200
committerLászló Németh <nemeth@numbertext.org>2013-10-25 08:35:41 +0200
commit223e1295b8f553228951d5165d8c3ee052c45944 (patch)
treea8e17258ce69b89bfa67e1b9edac3640163d4502
parent090d7f01fdbdb0abff52b86b5145216c6835acfc (diff)
librelogo: fix division with measurements
Change-Id: I2204002533bbb3e7c801b3228b0310a42b19a882 (cherry picked from commit 7744c4a0016be338c6c14b14f620d8af7d76111e)
-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 216bb0f0e19d..bfe568652e14 100644
--- a/librelogo/source/LibreLogo/LibreLogo.py
+++ b/librelogo/source/LibreLogo/LibreLogo.py
@@ -1352,7 +1352,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["],
@@ -1424,9 +1424,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