Pyparsing help

rh0dium steven.klass at gmail.com
Sat Mar 22 17:11:16 EDT 2008


Hi all,

I am struggling with parsing the following data:

test1 = """
Technology      {
                name                            = "gtc"
                dielectric                      = 2.75e-05
                unitTimeName                    = "ns"
                timePrecision                   = 1000
                unitLengthName                  = "micron"
                lengthPrecision                 = 1000
                gridResolution                  = 5
                unitVoltageName                 = "v"
                voltagePrecision                = 1000000
                unitCurrentName                 = "ma"
                currentPrecision                = 1000
                unitPowerName                   = "pw"
                powerPrecision                  = 1000
                unitResistanceName              = "kohm"
                resistancePrecision             = 10000000
                unitCapacitanceName             = "pf"
                capacitancePrecision            = 10000000
                unitInductanceName              = "nh"
                inductancePrecision             = 100
}

Tile            "unit" {
                width                           = 0.22
                height                          = 1.69
}

Layer           "PRBOUNDARY" {
                layerNumber                     = 0
                maskName                        = ""
                visible                         = 1
                selectable                      = 1
                blink                           = 0
                color                           = "cyan"
                lineStyle                       = "solid"
                pattern                         = "blank"
                pitch                           = 0
                defaultWidth                    = 0
                minWidth                        = 0
                minSpacing                      = 0
}

Layer           "METAL2" {
                layerNumber                     = 36
                maskName                        = "metal2"
                isDefaultLayer                  = 1
                visible                         = 1
                selectable                      = 1
                blink                           = 0
                color                           = "yellow"
                lineStyle                       = "solid"
                pattern                         = "blank"
                pitch                           = 0.46
                defaultWidth                    = 0.2
                minWidth                        = 0.2
                minSpacing                      = 0.21
                fatContactThreshold             = 1.4
                maxSegLenForRC                  = 2000
                unitMinResistance               = 6.1e-05
                unitNomResistance               = 6.3e-05
                unitMaxResistance               = 6.9e-05
                unitMinHeightFromSub            = 1.21
                unitNomHeightFromSub            = 1.237
                unitMaxHeightFromSub            = 1.267
                unitMinThickness                = 0.25
                unitNomThickness                = 0.475
                unitMaxThickness                = 0.75
                fatTblDimension                 = 3
                fatTblThreshold                 = (0,0.39,10.005)
                fatTblParallelLength            = (0,1,0)
                fatTblSpacing                   = (0.21,0.24,0.6,
                                                   0.24,0.24,0.6,
                                                   0.6,0.6,0.6)
                minArea                         = 0.144
}
"""

So it looks like starting from the inside out
I have an key and a value where the value can be a QuotedString,
Word(num), or a list of nums

So my code to catch this looks like this..

    atflist = Suppress("(") + commaSeparatedList + Suppress(")")
    atfstr = quotedString.setParseAction(removeQuotes)
    atfvalues = ( Word(nums) | atfstr | atflist )

    l = ("36", '"metal2"', '(0.21,0.24,0.6,0.24,0.24,0.6)')

    for x in l:
        print atfvalues.parseString(x)

But this isn't passing the list commaSeparatedList.  Can someone point
out my errors?

As a side note:  Is this the right approach to using pyparsing.  Do we
start from the inside and work our way out or should I have started
with looking at the bigger picture ( keyword + "{" + OneOrMore key /
vals + "}" + )  I started there but could figure out how to look
multiline - I'm assuming I'd just join them all up?

Thanks




More information about the Python-list mailing list