diff options
author | Paul McGuire <ptmcg@austin.rr.com> | 2015-03-25 11:13:26 +0000 |
---|---|---|
committer | Paul McGuire <ptmcg@austin.rr.com> | 2015-03-25 11:13:26 +0000 |
commit | 70869715b99cdb0a24193e86f99bc954397bb509 (patch) | |
tree | d08fd649cd311bd9d5ad068574199e0c8fcb3782 /src | |
parent | 540d2bc30990056245481426d8b00c5edc490f03 (diff) | |
download | pyparsing-git-70869715b99cdb0a24193e86f99bc954397bb509.tar.gz |
- update to srange to accept unicode literals in the input StringEnd
- enhanced version of replaceWith
Diffstat (limited to 'src')
-rw-r--r-- | src/CHANGES | 13 | ||||
-rw-r--r-- | src/pyparsing.py | 12 | ||||
-rw-r--r-- | src/unitTests.py | 11 |
3 files changed, 26 insertions, 10 deletions
diff --git a/src/CHANGES b/src/CHANGES index 2fe5905..f1d1130 100644 --- a/src/CHANGES +++ b/src/CHANGES @@ -2,6 +2,15 @@ Change Log
==========
+Version 2.0.4 -
+---------------------------
+- Slight mod to srange to accept unicode literals for the input string,
+ such as "[а-яА-Я]" instead of "[\u0430-\u044f\u0410-\u042f]". Thanks
+ to Alexandr Suchkov for the patch!
+
+- Enhanced implementation of replaceWith
+
+
Version 2.0.3 -
---------------------------
- Fixed escaping behavior in QuotedString. Formerly, only quotation
@@ -719,7 +728,7 @@ Version 1.4.8 - October, 2007 the new features.
- Added performance speedup to grammars using operatorPrecedence,
- instigated by Stefan Reichr - thanks for the feedback, Stefan!
+ instigated by Stefan Reichör - thanks for the feedback, Stefan!
- Fixed bug/typo when deleting an element from a ParseResults by
using the element's results name.
@@ -1414,7 +1423,7 @@ Version 1.3 - March, 2005 (Big thanks to Gavin Panella!)
- Added constant alphas8bit to include the following 8-bit characters:
-
+ ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ
- Added srange() function to simplify definition of Word elements, using
regexp-like '[A-Za-z0-9]' syntax. This also simplifies referencing
diff --git a/src/pyparsing.py b/src/pyparsing.py index 7b82f71..ff1ff60 100644 --- a/src/pyparsing.py +++ b/src/pyparsing.py @@ -70,6 +70,9 @@ import re import sre_constants
import collections
import pprint
+import functools
+import itertools
+
#~ sys.stderr.write( "testing pyparsing module, version %s, %s\n" % (__version__,__versionTime__ ) )
__all__ = [
@@ -3352,7 +3355,7 @@ stringEnd = StringEnd().setName("stringEnd") _escapedPunc = Word( _bslash, r"\[]-*.$+^?()~ ", exact=2 ).setParseAction(lambda s,l,t:t[0][1])
_escapedHexChar = Regex(r"\\0?[xX][0-9a-fA-F]+").setParseAction(lambda s,l,t:unichr(int(t[0].lstrip(r'\0x'),16)))
_escapedOctChar = Regex(r"\\0[0-7]+").setParseAction(lambda s,l,t:unichr(int(t[0][1:],8)))
-_singleChar = _escapedPunc | _escapedHexChar | _escapedOctChar | Word(printables, excludeChars=r'\]', exact=1)
+_singleChar = _escapedPunc | _escapedHexChar | _escapedOctChar | Word(printables, excludeChars=r'\]', exact=1) | Regex(r"\w", re.UNICODE)
_charRange = Group(_singleChar + Suppress("-") + _singleChar)
_reBracketExpr = Literal("[") + Optional("^").setResultsName("negate") + Group( OneOrMore( _charRange | _singleChar ) ).setResultsName("body") + "]"
@@ -3392,9 +3395,10 @@ def replaceWith(replStr): """Helper method for common parse actions that simply return a literal value. Especially
useful when used with C{L{transformString<ParserElement.transformString>}()}.
"""
- def _replFunc(*args):
- return [replStr]
- return _replFunc
+ #def _replFunc(*args):
+ # return [replStr]
+ #return _replFunc
+ return functools.partial(next, itertools.repeat([replStr]))
def removeQuotes(s,l,t):
"""Helper parse action for removing quotation marks from parsed quoted strings.
diff --git a/src/unitTests.py b/src/unitTests.py index cefd763..84fe9c9 100644 --- a/src/unitTests.py +++ b/src/unitTests.py @@ -854,6 +854,8 @@ class ReStringRangeTest(ParseTestCase): (r"[A-]"),
(r"[-A]"),
(r"[\x21]"),
+ #(r"[а-яА-ЯёЁA-Z$_\041α-ω]".decode('utf-8')),
+ (u'[\u0430-\u044f\u0410-\u042f\u0451\u0401ABCDEFGHIJKLMNOPQRSTUVWXYZ$_\041\u03b1-\u03c9]'),
)
expectedResults = (
"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
@@ -877,12 +879,13 @@ class ReStringRangeTest(ParseTestCase): "A-",
"-A",
"!",
+ u"абвгдежзийклмнопрстуфхцчшщъыьэюяАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯёЁABCDEFGHIJKLMNOPQRSTUVWXYZ$_!αβγδεζηθικλμνξοπρςστυφχψω",
)
for test in zip( testCases, expectedResults ):
t,exp = test
res = pyparsing.srange(t)
- #~ print t,"->",res
- assert res == exp, "srange error, srange(%s)->'%r', expected '%r'" % (t, res, exp)
+ #print_(t,"->",res)
+ assert res == exp, "srange error, srange(%r)->'%r', expected '%r'" % (t, res, exp)
class SkipToParserTests(ParseTestCase):
def runTest(self):
@@ -1376,8 +1379,8 @@ class UpcaseDowncaseUnicode(ParseTestCase): from __builtin__ import unichr
a = '\u00bfC\u00f3mo esta usted?'
- ualphas = "".join( [ unichr(i) for i in range(sys.maxunicode)
- if unichr(i).isalpha() ] )
+ ualphas = "".join( unichr(i) for i in range(sys.maxunicode)
+ if unichr(i).isalpha() )
uword = pp.Word(ualphas).setParseAction(pp.upcaseTokens)
print_ = lambda *args: None
|