diff options
author | ptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b> | 2012-11-17 22:51:07 +0000 |
---|---|---|
committer | ptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b> | 2012-11-17 22:51:07 +0000 |
commit | 1eea6da9180718c50751a70bfc7a242afbc36051 (patch) | |
tree | 5f6a7c4da23d8bb475225fd05193b5dab6574984 /src/pyparsing_py3.py | |
parent | e60eadf334dd588c7bce4358982a89d483a38ee0 (diff) | |
parent | 2204995d930d357a0a9ef7148baf9cef26ef5195 (diff) | |
download | pyparsing-1eea6da9180718c50751a70bfc7a242afbc36051.tar.gz |
Branch off 1.5.x path for Python 2.x compatibility
git-svn-id: svn://svn.code.sf.net/p/pyparsing/code/branches/pyparsing_1.5.x@243 9bf210a0-9d2d-494c-87cf-cfb32e7dff7b
Diffstat (limited to 'src/pyparsing_py3.py')
-rw-r--r-- | src/pyparsing_py3.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/pyparsing_py3.py b/src/pyparsing_py3.py index d427ca7..4a6bd74 100644 --- a/src/pyparsing_py3.py +++ b/src/pyparsing_py3.py @@ -59,7 +59,7 @@ The pyparsing module handles some of the problems that are typically vexing when """
__version__ = "1.5.7"
-__versionTime__ = "3 August 2012 05:00"
+__versionTime__ = "17 November 2012 16:18"
__author__ = "Paul McGuire <ptmcg@users.sourceforge.net>"
import string
@@ -89,7 +89,7 @@ __all__ = [ 'punc8bit', 'pythonStyleComment', 'quotedString', 'removeQuotes', 'replaceHTMLEntity',
'replaceWith', 'restOfLine', 'sglQuotedString', 'srange', 'stringEnd',
'stringStart', 'traceParseAction', 'unicodeString', 'upcaseTokens', 'withAttribute',
-'indentedBlock', 'originalTextFor', 'ungroup',
+'indentedBlock', 'originalTextFor', 'ungroup', 'infixNotation',
]
_MAX_INT = sys.maxsize
@@ -3346,7 +3346,7 @@ opAssoc = _Constants() opAssoc.LEFT = object()
opAssoc.RIGHT = object()
-def operatorPrecedence( baseExpr, opList ):
+def infixNotation( baseExpr, opList, lpar=Suppress('('), rpar=Suppress(')') ):
"""Helper method for constructing grammars of expressions made up of
operators working in a precedence hierarchy. Operators may be unary or
binary, left- or right-associative. Parse actions can also be attached
@@ -3369,9 +3369,11 @@ def operatorPrecedence( baseExpr, opList ): - parseAction is the parse action to be associated with
expressions matching this operator expression (the
parse action tuple member may be omitted)
+ - lpar - expression for matching left-parentheses (default=Suppress('('))
+ - rpar - expression for matching right-parentheses (default=Suppress(')'))
"""
ret = Forward()
- lastExpr = baseExpr | ( Suppress('(') + ret + Suppress(')') )
+ lastExpr = baseExpr | ( lpar + ret + rpar )
for i,operDef in enumerate(opList):
opExpr,arity,rightLeftAssoc,pa = (operDef + (None,))[:4]
if arity == 3:
@@ -3416,6 +3418,7 @@ def operatorPrecedence( baseExpr, opList ): lastExpr = thisExpr
ret << lastExpr
return ret
+operatorPrecedence = infixNotation
dblQuotedString = Regex(r'"(?:[^"\n\r\\]|(?:"")|(?:\\x[0-9a-fA-F]+)|(?:\\.))*"').setName("string enclosed in double quotes")
sglQuotedString = Regex(r"'(?:[^'\n\r\\]|(?:'')|(?:\\x[0-9a-fA-F]+)|(?:\\.))*'").setName("string enclosed in single quotes")
|