Fix multiline read of mixed statements (%XXX*% followed by DNN*)

We now check if there is a %XXX*% command inside the line before
considering it a multiline statement.
This commit is contained in:
Paulo Henrique Silva 2015-05-21 16:15:55 -03:00
parent 2fe5f36db2
commit aff36a4dca
3 changed files with 20 additions and 1 deletions

View file

@ -241,10 +241,11 @@ class GerberParser(object):
continue
# deal with multi-line parameters
if line.startswith("%") and not line.endswith("%"):
if line.startswith("%") and not line.endswith("%") and not "%" in line[1:]:
oldline = line
continue
did_something = True # make sure we do at least one loop
while did_something and len(line) > 0:
did_something = False
@ -292,6 +293,7 @@ class GerberParser(object):
# parameter
(param, r) = _match_one_from_many(self.PARAM_STMT, line)
if param:
if param["param"] == "FS":
stmt = FSParamStmt.from_dict(param)

View file

@ -0,0 +1,9 @@
G75*
G71*
%OFA0B0*%
%FSLAX23Y23*%
%IPPOS*%
%LPD*%
%ADD10C,0.1*%
%LPD*%D10*
M02*

View file

@ -11,11 +11,19 @@ from .tests import *
TOP_COPPER_FILE = os.path.join(os.path.dirname(__file__),
'resources/top_copper.GTL')
MULTILINE_READ_FILE = os.path.join(os.path.dirname(__file__),
'resources/multiline_read.ger')
def test_read():
top_copper = read(TOP_COPPER_FILE)
assert(isinstance(top_copper, GerberFile))
def test_multiline_read():
multiline = read(MULTILINE_READ_FILE)
assert(isinstance(multiline, GerberFile))
assert_equal(10, len(multiline.statements))
def test_comments_parameter():
top_copper = read(TOP_COPPER_FILE)
assert_equal(top_copper.comments[0], 'This is a comment,:')