summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2013-09-14 12:55:40 +0000
committerptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2013-09-14 12:55:40 +0000
commit83723b9a28212bfd43df400450eca1896c7d32c9 (patch)
tree251c598b5f45f9df81f0262487625843e3ce72f1
parent7d78d891253779e91d5dbd73b2391296bd487b3a (diff)
downloadpyparsing-83723b9a28212bfd43df400450eca1896c7d32c9.tar.gz
Added locatedExpr helper method
Removed deprecation of '<<' operator git-svn-id: svn://svn.code.sf.net/p/pyparsing/code/trunk@260 9bf210a0-9d2d-494c-87cf-cfb32e7dff7b
-rw-r--r--src/CHANGES10
-rw-r--r--src/pyparsing.py20
2 files changed, 20 insertions, 10 deletions
diff --git a/src/CHANGES b/src/CHANGES
index 0a6bc13..39cc397 100644
--- a/src/CHANGES
+++ b/src/CHANGES
@@ -2,11 +2,19 @@
Change Log
==========
-Version 2.0.1 -
+Version 2.0.2 -
-----------------------
- Extended "expr(name)" shortcut (same as "expr.setResultsName(name)")
to accept "expr()" as a shortcut for "expr.copy()".
+- Added "locatedExpr(expr)" helper, to decorate any returned tokens
+ with their location within the input string.
+
+- Removed deprecation warnings when using '<<' for Forward expression
+ assignment. '<<=' is still preferred, but '<<' will be retained
+ for cases whre '<<=' operator is not suitable (such as in defining
+ lambda expressions).
+
Version 2.0.1 - July, 2013
--------------------------
diff --git a/src/pyparsing.py b/src/pyparsing.py
index f96a0fb..5aa2df6 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 August 2013 22:22"
+__versionTime__ = "14 September 2013 07:34"
__author__ = "Paul McGuire <ptmcg@users.sourceforge.net>"
import string
@@ -88,7 +88,7 @@ __all__ = [
'punc8bit', 'pythonStyleComment', 'quotedString', 'removeQuotes', 'replaceHTMLEntity',
'replaceWith', 'restOfLine', 'sglQuotedString', 'srange', 'stringEnd',
'stringStart', 'traceParseAction', 'unicodeString', 'upcaseTokens', 'withAttribute',
-'indentedBlock', 'originalTextFor', 'ungroup', 'infixNotation',
+'indentedBlock', 'originalTextFor', 'ungroup', 'infixNotation','locatedExpr',
]
PY_3 = sys.version.startswith('3')
@@ -141,7 +141,6 @@ else:
except AttributeError:
continue
-
def _xml_escape(data):
"""Escape &, <, >, ", ', etc. in a string of data."""
@@ -2839,7 +2838,7 @@ class Forward(ParseElementEnhance):
def __init__( self, other=None ):
super(Forward,self).__init__( other, savelist=False )
- def __ilshift__( self, other ):
+ def __lshift__( self, other ):
if isinstance( other, basestring ):
other = ParserElement.literalStringClass(other)
self.expr = other
@@ -2853,11 +2852,8 @@ class Forward(ParseElementEnhance):
self.ignoreExprs.extend(self.expr.ignoreExprs)
return self
- def __lshift__(self, other):
- warnings.warn("Operator '<<' is deprecated, use '<<=' instead",
- DeprecationWarning,stacklevel=2)
- self <<= other
- return None
+ def __ilshift__(self, other):
+ return self << other
def leaveWhitespace( self ):
self.skipWhitespace = False
@@ -3250,6 +3246,12 @@ def ungroup(expr):
if all but one are non-empty."""
return TokenConverter(expr).setParseAction(lambda t:t[0])
+def locatedExpr(expr):
+ """Helper to decorate a returned token with its location in the input string"""
+ locator = Empty().setParseAction(lambda s,l,t: l)
+ return Group(locator("location") + expr("value"))
+
+
# convenience constants for positional expressions
empty = Empty().setName("empty")
lineStart = LineStart().setName("lineStart")