R
rh0dium
Hi all,
I almost did my first pyparsing without help but here we go again.
Let's start with my code. The sample data is listed below.
# This will gather the following ( "NamedPin" "PinDirection"
"OptionalSignal" )
guts = Group( LPAR.suppress() +
quotedString.setParseAction(removeQuotes).setResultsName("name") +
quotedString.setParseAction(removeQuotes).setResultsName("direction")
+
Optional(quotedString.setParseAction(removeQuotes).setResultsName("signal"))
+ RPAR.suppress())
# This will simply wrap the Cell Info around it
cell = Group( Literal("dbSetCellPortTypes").suppress() +
quotedString.setParseAction(removeQuotes).setResultsName("library") +
quotedString.setParseAction(removeQuotes).setResultsName("name") +
Literal("'").suppress() + LPAR.suppress() +
OneOrMore(guts).setResultsName("pins") + RPAR.suppress() ) +
Literal("#f").suppress() | Literal("#t").suppress()
# This grabs many cells
cells = OneOrMore(cell)
OK and it sorta works if I do the following:
x = cells.parseString(data)
print x[0].asDict()
reveals
{'pins': ([(['A', 'Input'], {'direction': [('Input', 1)], 'name':
[('A', 0)]}), (['B', 'Input'], {'direction': [('Input', 1)], 'name':
[('B', 0)]}), (['Y', 'Output'], {'direction': [('Output', 1)], 'name':
[('Y', 0)]}), (['VDD', 'Inout', 'Power'], {'direction': [('Inout',
1)], 'name': [('VDD', 0)], 'signal': [('Power', 2)]}), (['VSS',
'Inout', 'Ground'], {'direction': [('Inout', 1)], 'name': [('VSS',
0)], 'signal': [('Ground', 2)]})], {}), 'name': 'AND2X1', 'library':
'stdcell130'}
As you can see the Pins is all jacked up and I want is not that. I
want the following
{ 'name': 'AND2X1',
'library':'stdcell130'
'pins': [ { 'name': 'VSS', 'direction':'Inout', 'signal':'Ground'},
{ 'name': 'VDD', 'direction':'Inout', 'signal':'Power'},
{ 'name': 'A', 'direction':'Input' },
{ 'name': 'B', 'direction':'Input' },
{ 'name': 'Y', 'direction':'Output' } ]
}
What did I do wrong in my code..
Thanks again!
]
I would expect my results to look like this:
But to get any info I must do this
print x[0].asDict()
which is not really what want.
What I expect is this:
[
data = """dbSetCellPortTypes "stdcell130" "AND2X1" '(
("A" "Input" )
("B" "Input" )
("Y" "Output" )
("VDD" "Inout" "Power" )
("VSS" "Inout" "Ground" )
) #f
dbSetCellPortTypes "stdcell130" "AND2X2" '(
("A" "Input" )
("B" "Input" )
("Y" "Output" )
("VDD" "Inout" "Power" )
("VSS" "Inout" "Ground" )
) #f """
I almost did my first pyparsing without help but here we go again.
Let's start with my code. The sample data is listed below.
# This will gather the following ( "NamedPin" "PinDirection"
"OptionalSignal" )
guts = Group( LPAR.suppress() +
quotedString.setParseAction(removeQuotes).setResultsName("name") +
quotedString.setParseAction(removeQuotes).setResultsName("direction")
+
Optional(quotedString.setParseAction(removeQuotes).setResultsName("signal"))
+ RPAR.suppress())
# This will simply wrap the Cell Info around it
cell = Group( Literal("dbSetCellPortTypes").suppress() +
quotedString.setParseAction(removeQuotes).setResultsName("library") +
quotedString.setParseAction(removeQuotes).setResultsName("name") +
Literal("'").suppress() + LPAR.suppress() +
OneOrMore(guts).setResultsName("pins") + RPAR.suppress() ) +
Literal("#f").suppress() | Literal("#t").suppress()
# This grabs many cells
cells = OneOrMore(cell)
OK and it sorta works if I do the following:
x = cells.parseString(data)
print x[0].asDict()
reveals
{'pins': ([(['A', 'Input'], {'direction': [('Input', 1)], 'name':
[('A', 0)]}), (['B', 'Input'], {'direction': [('Input', 1)], 'name':
[('B', 0)]}), (['Y', 'Output'], {'direction': [('Output', 1)], 'name':
[('Y', 0)]}), (['VDD', 'Inout', 'Power'], {'direction': [('Inout',
1)], 'name': [('VDD', 0)], 'signal': [('Power', 2)]}), (['VSS',
'Inout', 'Ground'], {'direction': [('Inout', 1)], 'name': [('VSS',
0)], 'signal': [('Ground', 2)]})], {}), 'name': 'AND2X1', 'library':
'stdcell130'}
As you can see the Pins is all jacked up and I want is not that. I
want the following
{ 'name': 'AND2X1',
'library':'stdcell130'
'pins': [ { 'name': 'VSS', 'direction':'Inout', 'signal':'Ground'},
{ 'name': 'VDD', 'direction':'Inout', 'signal':'Power'},
{ 'name': 'A', 'direction':'Input' },
{ 'name': 'B', 'direction':'Input' },
{ 'name': 'Y', 'direction':'Output' } ]
}
What did I do wrong in my code..
Thanks again!
]
I would expect my results to look like this:
But to get any info I must do this
print x[0].asDict()
which is not really what want.
What I expect is this:
[
data = """dbSetCellPortTypes "stdcell130" "AND2X1" '(
("A" "Input" )
("B" "Input" )
("Y" "Output" )
("VDD" "Inout" "Power" )
("VSS" "Inout" "Ground" )
) #f
dbSetCellPortTypes "stdcell130" "AND2X2" '(
("A" "Input" )
("B" "Input" )
("Y" "Output" )
("VDD" "Inout" "Power" )
("VSS" "Inout" "Ground" )
) #f """