Re: [Pyparsing] Grouping when using asList()
Brought to you by:
ptmcg
From: Paul M. <pa...@al...> - 2008-03-06 22:08:02
|
Joshua - You already had most of the pieces there, just a couple of gaps around a little-used feature. >>>One question: ("defs") is a call to what Groups() returns, but I'm not following. Can you point me to something in the docs that explains what is done when you call a pyparsing expression?<<< Let's say you have this form for a date string: twoDigitInt = Word(nums,exact=2) date = twoDigitInt + '/' + twoDigitInt + '/' + twoDigitInt The old way to assign results names was (I'm using US date format mm/dd/yy convention): date = twoDigitInt.setResultsName("month") + '/' + twoDigitInt.setResultsName("day") + '/' + twoDigitInt.setResultsName("year") I *really* wanted to encourage people to use results names, so I made ParserElements "callable", and having the __call__ function call setResultsName, thus supporting the following shortened syntax: date = twoDigitInt("month") + '/' + twoDigitInt("day") + '/' + twoDigitInt("year") Try to look past the "it's a function call" to "this is a lot easier to specify a results name than that old way!". (However, if you need to add the listAllMatches attribute, this still requires the explicit call to setResultsName.) I hope that's not too confusing. -- Paul |