summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2014-04-09 13:56:20 +0000
committerptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2014-04-09 13:56:20 +0000
commitf267f3121cec683b164854e72179c0a97904a383 (patch)
treeb7b2fe775a59c7293f9cfa662eb5e0c915c1f98a
parent6b43e5e3d4562f6f6bf572a8a6d0327ab3eeb696 (diff)
downloadpyparsing-f267f3121cec683b164854e72179c0a97904a383.tar.gz
Fixed markInputline bug; reverted some <<= to << changes to avoid local/nonlocal reference problems
git-svn-id: svn://svn.code.sf.net/p/pyparsing/code/trunk@263 9bf210a0-9d2d-494c-87cf-cfb32e7dff7b
-rw-r--r--src/CHANGES6
-rw-r--r--src/pyparsing.py18
-rw-r--r--src/unitTests.py22
3 files changed, 34 insertions, 12 deletions
diff --git a/src/CHANGES b/src/CHANGES
index c2a0c3e..fe358a2 100644
--- a/src/CHANGES
+++ b/src/CHANGES
@@ -2,8 +2,8 @@
Change Log
==========
-Version 2.0.2 -
------------------------
+Version 2.0.2 - April, 2014
+---------------------------
- Extended "expr(name)" shortcut (same as "expr.setResultsName(name)")
to accept "expr()" as a shortcut for "expr.copy()".
@@ -41,6 +41,8 @@ Version 2.0.2 -
second default return value argument is supported, just as in
dict.pop().
+- Fixed bug in markInputline, thanks for reporting this, Matt Grant!
+
- Cleaned up my unit test environment, now runs with Python 2.6 and
3.3.
diff --git a/src/pyparsing.py b/src/pyparsing.py
index 60198ca..799a150 100644
--- a/src/pyparsing.py
+++ b/src/pyparsing.py
@@ -58,7 +58,7 @@ The pyparsing module handles some of the problems that are typically vexing when
"""
__version__ = "2.0.2"
-__versionTime__ = "21 September 2013 10:45"
+__versionTime__ = "8 April 2014 08:55"
__author__ = "Paul McGuire <ptmcg@users.sourceforge.net>"
import string
@@ -204,8 +204,8 @@ class ParseBaseException(Exception):
line_str = self.line
line_column = self.column - 1
if markerString:
- line_str = "".join(line_str[:line_column],
- markerString, line_str[line_column:])
+ line_str = "".join((line_str[:line_column],
+ markerString, line_str[line_column:]))
return line_str.strip()
def __dir__(self):
return "loc msg pstr parserElement lineno col line " \
@@ -2948,7 +2948,7 @@ class Forward(ParseElementEnhance):
return super(Forward,self).copy()
else:
ret = Forward()
- ret << self
+ ret <<= self
return ret
class _ForwardNoRecurse(Forward):
@@ -3179,7 +3179,7 @@ def matchPreviousExpr(expr):
"""
rep = Forward()
e2 = expr.copy()
- rep << e2
+ rep <<= e2
def copyTokenToRepeater(s,l,t):
matchTokens = _flatten(t.asList())
def mustMatchTheseTokens(s,l,t):
@@ -3548,9 +3548,9 @@ def infixNotation( baseExpr, opList, lpar=Suppress('('), rpar=Suppress(')') ):
raise ValueError("operator must indicate right or left associativity")
if pa:
matchExpr.setParseAction( pa )
- thisExpr << ( matchExpr | lastExpr )
+ thisExpr <<= ( matchExpr | lastExpr )
lastExpr = thisExpr
- ret << lastExpr
+ ret <<= lastExpr
return ret
operatorPrecedence = infixNotation
@@ -3606,9 +3606,9 @@ def nestedExpr(opener="(", closer=")", content=None, ignoreExpr=quotedString.cop
raise ValueError("opening and closing arguments must be strings if no content expression is given")
ret = Forward()
if ignoreExpr is not None:
- ret << Group( Suppress(opener) + ZeroOrMore( ignoreExpr | ret | content ) + Suppress(closer) )
+ ret <<= Group( Suppress(opener) + ZeroOrMore( ignoreExpr | ret | content ) + Suppress(closer) )
else:
- ret << Group( Suppress(opener) + ZeroOrMore( ret | content ) + Suppress(closer) )
+ ret <<= Group( Suppress(opener) + ZeroOrMore( ret | content ) + Suppress(closer) )
return ret
def indentedBlock(blockStatementExpr, indentStack, indent=True):
diff --git a/src/unitTests.py b/src/unitTests.py
index 468952f..915a788 100644
--- a/src/unitTests.py
+++ b/src/unitTests.py
@@ -2153,6 +2153,24 @@ class SumParseResultsTest(ParseTestCase):
assert expected == result, \
"Failed to parse '%s' correctly, \nexpected '%s', got '%s'" % (test,expected,result)
+class MarkInputLineTest(ParseTestCase):
+ def runTest(self):
+
+ samplestr1 = "DOB 100-10-2010;more garbage\nID PARI12345678;more garbage"
+
+ from pyparsing import Regex, Word, alphanums, restOfLine
+ dob_ref = "DOB" + Regex(r"\d{2}-\d{2}-\d{4}")("dob")
+
+ try:
+ res = dob_ref.parseString(samplestr1)
+ except ParseException as pe:
+ outstr = pe.markInputline()
+ print_(outstr)
+ assert outstr == "DOB >!<100-10-2010;more garbage", "did not properly create marked input line"
+ else:
+ assert False, "test construction failed - should have raised an exception"
+
+
class MiscellaneousParserTests(ParseTestCase):
def runTest(self):
import pyparsing
@@ -2358,6 +2376,7 @@ def makeTestSuite():
suite.addTest( OptionalEachTest() )
suite.addTest( SumParseResultsTest() )
suite.addTest( WordExcludeTest() )
+ suite.addTest( MarkInputLineTest() )
suite.addTest( MiscellaneousParserTests() )
if TEST_USING_PACKRAT:
# retest using packrat parsing (disable those tests that aren't compatible)
@@ -2377,7 +2396,8 @@ def makeTestSuiteTemp():
suite = TestSuite()
suite.addTest( PyparsingTestInit() )
#~ suite.addTest( OptionalEachTest() )
- suite.addTest( RepeaterTest() )
+ #~ suite.addTest( RepeaterTest() )
+ suite.addTest( MarkInputLineTest() )
return suite