On Mar 22, 6:30 pm, Paul McGuire <[EMAIL PROTECTED]> wrote:
> Oof, I see that you have multiple "Layer" entries, with different
> qualifying labels.  Since the dicts use "Layer" as the key, you only
> get the last "Layer" value, with qualifier "PRBOUNDARY", and lose the
> "Layer" for "METAL2".  To fix this, you'll have to move the optional
> alias term to the key, and merge "Layer" and "PRBOUNDARY" into a
> single key, perhaps "Layer/PRBOUNDARY" or "Layer(PRBOUNDARY)" - a
> parse action should take care of this for you.  Unfortnately, these
> forms will not allow you to use object attribute form
> (md.Layer.lineStyle), you will have to use dict access form
> (md["Layer(PRBOUNDARY)"].lineStyle), since these keys have characters
> that are not valid attribute name characters.
>
> Or you could add one more level of Dict nesting to your grammar, to
> permit access like "md.Layer.PRBOUNDARY.lineStyle".
>
> -- Paul

OK - We'll I got as far as you did but I did it a bit differently..
Then I merged some of your data with my data.  But Now I am at the
point of adding another level of the dict and am struggling..  Here is
what I have..

    # parse actions
    LPAR = Literal("(")
    RPAR = Literal(")")
    LBRACE = Literal("{")
    RBRACE = Literal("}")
    EQUAL = Literal("=")

    # This will get the values all figured out..
        # "metal2" 1 6.05E-05 30
    cvtInt = lambda toks: int(toks[0])
    cvtReal = lambda toks: float(toks[0])

    integer = Combine(Optional(oneOf("+ -")) + Word(nums))\
        .setParseAction( cvtInt )
    real = Combine(Optional(oneOf("+ -")) + Word(nums) + "." +
                   Optional(Word(nums)) +
                   Optional(oneOf("e E")+Optional(oneOf("+ -"))
+Word(nums)))\
        .setParseAction( cvtReal )
    atfstr = quotedString.setParseAction(removeQuotes)
    atflist = Group( LPAR.suppress() +
                    delimitedList(real, ",") +
                    RPAR.suppress() )

    atfvalues = ( real | integer | atfstr | atflist )

    # Now this should work out a single line inside a section
        # maskName                        = "metal2"
        # isDefaultLayer                  = 1
        # visible                         = 1
        # fatTblSpacing                   = (0.21,0.24,0.6,
        #                                    0.6,0.6,0.6)
        # minArea                         = 0.144
    atfkeys = Word(alphanums)
    attrDict = dictOf( atfkeys , EQUAL.suppress() + atfvalues)

    # Now we need to take care of the "Metal2" { one or more
attrDict }
        # "METAL2" {
        #                 layerNumber                     = 36
        #                 maskName                        = "metal2"
        #                 isDefaultLayer                  = 1
        #                 visible                         = 1
        #                 fatTblSpacing                   =
(0.21,0.24,0.6,
        #
0.24,0.24,0.6,
        #
0.6,0.6,0.6)
        #                 minArea                         = 0.144
        # }
    attrType = dictOf(atfstr, LBRACE.suppress() + attrDict +
RBRACE.suppress())

    # Lastly we need to get the ones without attributes (Technology)
    attrType2 = LBRACE.suppress() + attrDict + RBRACE.suppress()
    mainDict = dictOf(atfkeys, attrType2 | attrType )

    md = mainDict.parseString(test1)


But I too am only getting the last layer.  I thought if broke out the
"alias" area and then built on that I'd be set but I did something
wrong.

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to