Pyparsing help

Paul McGuire ptmcg at austin.rr.com
Mon Mar 24 08:50:12 EDT 2008


On Mar 23, 4:04 pm, rh0dium <steven.kl... at gmail.com> wrote:
>
> I needed to tweak it a bit to ignore the comments..  Namely this fixed
> it up..
>
>     mainDict = dictOf(
>             Group(Word(alphas)+Optional(quotedString)),
>             Suppress("{") + attrDict + Suppress("}")
>             ) | cStyleComment.suppress()
>
> Thanks again.  Now I just need to figure out how to use your dicts to
> do some work..- Hide quoted text -
>
> - Show quoted text -

I'm glad this is coming around to some reasonable degree of completion
for you.  One last thought - your handling of comments is a bit crude,
and will not handle comments that crop up in the middle of dict
entries, as in:

    color    = /* using non-standard color during testing */
               "plum"

The more comprehensive way to handle comments is to call ignore.
Using ignore will propagate the comment handling to all embedded
expressions, so you only need to call ignore once on the top-most
pyparsing expression, as in:

    mainDict.ignore(cStyleComment)

Also, ignore does token suppression automatically.

-- Paul



More information about the Python-list mailing list