Re: [Pyparsing] parsing a simple Language
Brought to you by:
ptmcg
From: Paul M. <pt...@au...> - 2010-10-10 23:02:47
|
> I didn't complicate my minimal example with it, but I've got results > names set for initials, medials, and vowels. > Since the Regex option seems to be a likely path, you can use named capture groups in your re, and the Regex class will convert these to results names. syllable = Group(Regex(r"(?P<init>[sSbB])(?P<meds>[mMpP]*)(?P<vow>[aeiou]?)")) Iterate over your syllables, and you can access the fields as in: res = syllables.parseString(t) for syl in res.syllables: print syl.init, syl.meds, syl.vow - or - print "init: %(init)s meds:%(meds)s vow:%(vow)s" % syl > Thanks again for your help and insights, Paul -- once again, pyparsing > shines in all of its glory :-) > > d :) Thanks! As I said, this will be very interesting to see how it plays out. Pyparsing is already being used in zhpy to support Chinese language Python development in Python versions 2.x that pre-date support for Unicode identifiers. I'd also like to hear sometime just how you got involved in this application in the first place (perhaps you've already captured this in a blog post - just send me the post). Best regards, -- Paul |