summaryrefslogtreecommitdiff
path: root/gerber/am_read.py
diff options
context:
space:
mode:
authorPaulo Henrique Silva <ph.silva@gmail.com>2015-03-05 14:43:30 -0300
committerPaulo Henrique Silva <ph.silva@gmail.com>2015-03-05 14:43:30 -0300
commita13b981c1c2ea9ede39e9821d9ba818566f044de (patch)
treed7e1507bd389623e077da0d497b419edcfd9e53f /gerber/am_read.py
parent670d3fbbd7ebfb69bd223ac30b73ec47b195b380 (diff)
downloadgerbonara-a13b981c1c2ea9ede39e9821d9ba818566f044de.tar.gz
gerbonara-a13b981c1c2ea9ede39e9821d9ba818566f044de.tar.bz2
gerbonara-a13b981c1c2ea9ede39e9821d9ba818566f044de.zip
Fix tests for macros with no variables.
All AM*Primitive classes now handles float for all but the code modifiers. This simplifies the reading/parsing.
Diffstat (limited to 'gerber/am_read.py')
-rw-r--r--gerber/am_read.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/gerber/am_read.py b/gerber/am_read.py
index d1201b2..ade4389 100644
--- a/gerber/am_read.py
+++ b/gerber/am_read.py
@@ -32,6 +32,7 @@ class Token:
LEFT_PARENS = "("
RIGHT_PARENS = ")"
EQUALS = "="
+ EOF = "EOF"
def token_to_opcode(token):
@@ -71,7 +72,8 @@ class Scanner:
def peek(self):
if not self.eof():
return self.buff[self.n]
- return ""
+
+ return Token.EOF
def ungetc(self):
if self.n > 0:
@@ -104,6 +106,11 @@ class Scanner:
return s.strip()
+def print_instructions(instructions):
+ for opcode, argument in instructions:
+ print "%s %s" % (OpCode.str(opcode), str(argument) if argument is not None else "")
+
+
def read_macro(macro):
instructions = []
@@ -185,9 +192,10 @@ def read_macro(macro):
elif c == "0":
if is_primitive and not found_primitive_code:
instructions.append((OpCode.PUSH, scanner.readstr("*")))
+ found_primitive_code = True
else:
# decimal or integer disambiguation
- if scanner.peek() not in '.':
+ if scanner.peek() not in '.' or scanner.peek() == Token.EOF:
instructions.append((OpCode.PUSH, 0))
elif c in "123456789.":
@@ -207,7 +215,7 @@ def read_macro(macro):
instructions.append((token_to_opcode(pop()), None))
# at end, we either have a primitive or a equation
- if is_primitive:
+ if is_primitive and found_primitive_code:
instructions.append((OpCode.PRIM, primitive_code))
if is_equation:
@@ -221,8 +229,7 @@ if __name__ == '__main__':
instructions = read_macro(sys.argv[1])
print "insructions:"
- for opcode, argument in instructions:
- print "%s %s" % (OpCode.str(opcode), str(argument) if argument is not None else "")
+ print_instructions(instructions)
print "eval:"
for primitive in eval_macro(instructions):