Use pyparsing Group to add structure to the returned tokens. This will probably do the job:
gformat = (inst_del +
cmd_format('gerber-command') +
format_zeros +
format_notation +
'X' + pyp.Group(format_data)('x') +
'Y' + pyp.Group(format_data)('y') +
inst_end +
inst_del)
Pyparsing's default behavior is to just return a flat list of tokens, so as not to guess at structure just based on what terms are added in what order. For instance, if you had this:
aword = Word("A")
bword = Word("B")
cword = Word("C")
preface = aword + bword
body = cword
ending = aword + bword
totalExpr = preface + body + ending
print totalExpr.parseString("AA BB CCC A B").asList()
pyparsing would return just the list
['AA', 'BB', 'CCC', 'A', 'B']
If you want to apply structure (this is especially important to keep nested results names from stepping on each other, as you are seeing in the overlap of integer and decimal), use Group:
totalExpr = Group(preface) + body + Group(ending)
which gives:
[['AA', 'BB'], 'CCC', ['A', 'B']]
Here's how this would look if you added results names:
preface = aword("As") + bword("Bs")
body = cword
ending = aword("As") + bword("Bs")
totalExpr = Group(preface)("preface") + body("body") + Group(ending)("ending")
print totalExpr.parseString("AA BB CCC A B").dump()
Gives:
[['AA', 'BB'], 'CCC', ['A', 'B']]
- body: CCC
- ending: ['A', 'B']
- As: A
- Bs: B
- preface: ['AA', 'BB']
- As: AA
- Bs: BB
Because preface and ending are grouped, their duplicate names of "As" and "Bs" are kept separate.