Re: [Pyparsing] Word and Regex matching more than they should
Brought to you by:
ptmcg
From: Stuart L. <st...@vr...> - 2018-01-22 09:51:03
|
Hi Paul, On 22/01/18 19:42, Paul McGuire wrote: > Oddly enough, I could not specify the unicode range that you did, nor does sys.maxunicode work. This actually looks like a Python bug. I also see that your units is not quite as liberal as the unicode_printables one that I wrote, accepting only '%_/$' punctuation characters. I also see that your decimal expression accepts '_' spacers - the pyparsing_common.number expression that I used in the previous reply does not do this. > > I made a few other tweaks to your parser: > - added setName() calls, so that exceptions are a bit clearer looking ("expected unit-string" instead of "expected Re:('[a-zA-Z%_/$\\x80-\\xffffff]+')") > - used results names in hs_quantity so that the name-to-expression mapping was clearer (note that setName() sets the name of the expression itself, while setting results names sets the name to be used for the respective parsed results) Yeah, I've slowly been figuring those things out, latest code actually does make use of .setName quite a bit. > Out of curiosity, why Python2? I would only use Py2 for legacy work at this point, not for new projects. At the moment, we still have a legacy code base that uses Python 2.7… it is hoped (maybe this year, but who knows) that I can make the jump to 3.4+. We recently (late last year) dropped support for Debian Wheezy, which was the primary road block to adopting Python 3.x. Naturally though, I have to try and justify to the powers-at-be why we need to address the remaining technical debt. :-) For what it's worth, this particular library is written for both. While we use it in production on Python 2.7, others use it regularly on 3.4 and up. The unit tests cover 2.7, 3.4 and 3.5. I should add 3.6 in there too. -- _ ___ Stuart Longland - Systems Engineer \ /|_) | T: +61 7 3535 9619 \/ | \ | 38b Douglas Street F: +61 7 3535 9699 SYSTEMS Milton QLD 4064 http://www.vrt.com.au |