stumped by tricky logic

Dave davidworley at gmail.com
Sun Jan 29 17:55:12 CET 2006


So I'm trying to write a CSS preprocessor.

I want to add the ability to append a selector onto other selectors.
So, given the following code:
=========================================
#selector {

                          { property: value; property: value; }
        .other_selector   { property: value; property: value; }

        #selector_2 {

                 .more_selector { property: value; }

        }

}
=========================================

I want to return the following:
=========================================
#selector { property: value; property: value; }
#selector .other_selector { property: value; property: value; }
#selector #selector_2 .more_selector { property: value; }
=========================================

What I think I need to do is match the "{" character with its "}" pair,
then see if there's another "{" before a matching "}" - but that's
about as far as my brain will go. The actually code to make this
actually happen is not coming out when I type.

Any suggestions would be very appreciated. And handsomely rewarded (by
karma, not me).

- Dave




More information about the Python-list mailing list