summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulo Henrique Silva <ph.silva@gmail.com>2015-03-06 15:00:16 -0300
committerPaulo Henrique Silva <ph.silva@gmail.com>2015-03-06 15:00:16 -0300
commitf6dbe87c03c91cb4ba6672e7dee81475b86c1384 (patch)
tree7b025be4617d02aa35f68e341b886b33bc7d4f79
parent68619d4d5a7beb38dc81d953b43bf4196ca1d3a6 (diff)
downloadgerbonara-f6dbe87c03c91cb4ba6672e7dee81475b86c1384.tar.gz
gerbonara-f6dbe87c03c91cb4ba6672e7dee81475b86c1384.tar.bz2
gerbonara-f6dbe87c03c91cb4ba6672e7dee81475b86c1384.zip
Add support for unary minus operator on macro parsing
-rw-r--r--gerber/am_read.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/gerber/am_read.py b/gerber/am_read.py
index 05f3343..872c513 100644
--- a/gerber/am_read.py
+++ b/gerber/am_read.py
@@ -126,6 +126,9 @@ def read_macro(macro):
equation_left_side = 0
primitive_code = 0
+ unary_minus_allowed = False
+ unary_minus = False
+
if Token.EQUALS in block:
is_equation = True
else:
@@ -159,7 +162,14 @@ def read_macro(macro):
while not empty():
instructions.append((token_to_opcode(pop()), None))
+ unary_minus_allowed = True
+
elif c in Token.OPERATORS:
+ if c == Token.SUB and unary_minus_allowed:
+ unary_minus = True
+ unary_minus_allowed = False
+ continue
+
while not empty() and is_op(top()) and precedence(top()) >= precedence(c):
instructions.append((token_to_opcode(pop()), None))
@@ -204,8 +214,12 @@ def read_macro(macro):
if is_primitive and not found_primitive_code:
primitive_code = scanner.readint()
else:
- instructions.append((OpCode.PUSH, scanner.readfloat()))
+ n = scanner.readfloat()
+ if unary_minus:
+ unary_minus = False
+ n *= -1
+ instructions.append((OpCode.PUSH, n))
else:
# whitespace or unknown char
pass