summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2008-12-20 12:07:39 +0000
committerptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2008-12-20 12:07:39 +0000
commit48a871e461c5814cce482af338d7d6fd4c7871e0 (patch)
treebf5282f3e2f62f8aedfb990c630db948628d6c7f
parent8034c224cd41d2e681ca91d4df859786a2f7d20c (diff)
downloadpyparsing-48a871e461c5814cce482af338d7d6fd4c7871e0.tar.gz
Fixed bug in SkipTo when ignore argument is found at the beginning of the range of text to be skipped.
Fixed docstring in White class. Fixed obscure bug when calling __getitem__ of an object that replaces ParseResults during a parse action. git-svn-id: svn://svn.code.sf.net/p/pyparsing/code/src@176 9bf210a0-9d2d-494c-87cf-cfb32e7dff7b
-rw-r--r--CHANGES6
-rw-r--r--pyparsing.py23
-rw-r--r--pyparsing_py3.py28
3 files changed, 40 insertions, 17 deletions
diff --git a/CHANGES b/CHANGES
index a81fcc0..291fbd8 100644
--- a/CHANGES
+++ b/CHANGES
@@ -7,6 +7,12 @@ Version 1.5.2 - ???
- Fixed bug in SkipTo/failOn handling - caught by eagle eye
cpennington on the pyparsing wiki!
+- Fixed second bug in SkipTo when using the ignore constructor
+ argument, reported by Catherine Devlin, thanks!
+
+- Fixed obscure bug reported by Eike Welk when using a class
+ as a ParseAction with an errant __getitem__ method.
+
- Simplified exception stack traces when reporting parse
exceptions back to caller of parseString or parseFile - thanks
to a tip from Peter Otten on comp.lang.python.
diff --git a/pyparsing.py b/pyparsing.py
index 17e3b9e..bec5c33 100644
--- a/pyparsing.py
+++ b/pyparsing.py
@@ -59,7 +59,7 @@ The pyparsing module handles some of the problems that are typically vexing when
"""
__version__ = "1.5.2"
-__versionTime__ = "5 December 2008 10:27"
+__versionTime__ = "20 December 2008 05:55"
__author__ = "Paul McGuire <ptmcg@users.sourceforge.net>"
import string
@@ -110,6 +110,9 @@ if not _PY3K:
str(obj). If that fails with a UnicodeEncodeError, then it tries unicode(obj). It
then < returns the unicode object | encodes it with the default encoding | ... >.
"""
+ if isinstance(obj,unicode):
+ return obj
+
try:
# If this works, then _ustr(obj) has the same behaviour as str(obj), so
# it won't break any existing code.
@@ -309,7 +312,7 @@ class ParseResults(object):
else:
try:
self[name] = toklist[0]
- except (KeyError,TypeError):
+ except (KeyError,TypeError,IndexError):
self[name] = toklist
def __getitem__( self, i ):
@@ -1974,7 +1977,7 @@ class White(Token):
"""Special matching class for matching whitespace. Normally, whitespace is ignored
by pyparsing grammars. This class is included when some whitespace structures
are significant. Define with a string containing the whitespace characters to be
- matched; default is " \\t\\n". Also takes optional min, max, and exact arguments,
+ matched; default is " \\t\\r\\n". Also takes optional min, max, and exact arguments,
as defined for the Word class."""
whiteStrs = {
" " : "<SPC>",
@@ -2534,7 +2537,7 @@ class Each(ParseExpression):
raise ParseException(instring,loc,"Missing one or more required elements (%s)" % missing )
# add any unmatched Optionals, in case they have default values defined
- matchOrder += [ e for e in self.exprs if isinstance(e,Optional) and e.expr in tmpOpt ]
+ matchOrder += list(e for e in self.exprs if isinstance(e,Optional) and e.expr in tmpOpt)
resultlist = []
for e in matchOrder:
@@ -2815,9 +2818,7 @@ class SkipTo(ParseElementEnhance):
"""
def __init__( self, other, include=False, ignore=None, failOn=None ):
super( SkipTo, self ).__init__( other )
- if ignore is not None:
- self.expr = self.expr.copy()
- self.expr.ignore(ignore)
+ self.ignoreExpr = ignore
self.mayReturnEmpty = True
self.mayIndexError = False
self.includeMatch = include
@@ -2845,7 +2846,13 @@ class SkipTo(ParseElementEnhance):
failParse = True
raise ParseException(instring, loc, "Found expression " + str(self.failOn))
failParse = False
- loc = expr._skipIgnorables( instring, loc )
+ if self.ignoreExpr is not None:
+ while 1:
+ try:
+ loc = self.ignoreExpr.tryParse(instring,loc)
+ print "found ignoreExpr, advance to", loc
+ except ParseBaseException:
+ break
expr._parse( instring, loc, doActions=False, callPreParse=False )
skipText = instring[startLoc:loc]
if self.includeMatch:
diff --git a/pyparsing_py3.py b/pyparsing_py3.py
index 2a9da0d..a9d8412 100644
--- a/pyparsing_py3.py
+++ b/pyparsing_py3.py
@@ -59,7 +59,7 @@ The pyparsing module handles some of the problems that are typically vexing when
"""
__version__ = "1.5.2Py3"
-__versionTime__ = "8 November 2008 05:36"
+__versionTime__ = "20 December 2008 06:00"
__author__ = "Paul McGuire <ptmcg@users.sourceforge.net>"
import string
@@ -110,6 +110,9 @@ if not _PY3K:
str(obj). If that fails with a UnicodeEncodeError, then it tries unicode(obj). It
then < returns the unicode object | encodes it with the default encoding | ... >.
"""
+ if isinstance(obj,unicode):
+ return obj
+
try:
# If this works, then _ustr(obj) has the same behaviour as str(obj), so
# it won't break any existing code.
@@ -309,7 +312,7 @@ class ParseResults(object):
else:
try:
self[name] = toklist[0]
- except (KeyError,TypeError):
+ except (KeyError,TypeError,IndexError):
self[name] = toklist
def __getitem__( self, i ):
@@ -1974,7 +1977,7 @@ class White(Token):
"""Special matching class for matching whitespace. Normally, whitespace is ignored
by pyparsing grammars. This class is included when some whitespace structures
are significant. Define with a string containing the whitespace characters to be
- matched; default is " \\t\\n". Also takes optional min, max, and exact arguments,
+ matched; default is " \\t\\r\\n". Also takes optional min, max, and exact arguments,
as defined for the Word class."""
whiteStrs = {
" " : "<SPC>",
@@ -2208,7 +2211,10 @@ class ParseExpression(ParserElement):
elif isinstance( exprs, basestring ):
self.exprs = [ Literal( exprs ) ]
else:
- self.exprs = list( exprs )
+ try:
+ self.exprs = list( exprs )
+ except TypeError:
+ self.exprs = [ exprs ]
self.callPreparse = False
def __getitem__( self, i ):
@@ -2812,9 +2818,7 @@ class SkipTo(ParseElementEnhance):
"""
def __init__( self, other, include=False, ignore=None, failOn=None ):
super( SkipTo, self ).__init__( other )
- if ignore is not None:
- self.expr = self.expr.copy()
- self.expr.ignore(ignore)
+ self.ignoreExpr = ignore
self.mayReturnEmpty = True
self.mayIndexError = False
self.includeMatch = include
@@ -2842,7 +2846,13 @@ class SkipTo(ParseElementEnhance):
failParse = True
raise ParseException(instring, loc, "Found expression " + str(self.failOn))
failParse = False
- loc = expr._skipIgnorables( instring, loc )
+ if self.ignoreExpr is not None:
+ while 1:
+ try:
+ loc = self.ignoreExpr.tryParse(instring,loc)
+ print "found ignoreExpr, advance to", loc
+ except ParseBaseException:
+ break
expr._parse( instring, loc, doActions=False, callPreParse=False )
skipText = instring[startLoc:loc]
if self.includeMatch:
@@ -3195,7 +3205,7 @@ def oneOf( strs, caseless=False, useRegex=True ):
parseElementClass = Literal
if isinstance(strs,(list,tuple)):
- symbols = strs[:]
+ symbols = list(strs[:])
elif isinstance(strs,basestring):
symbols = strs.split()
else: