summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2012-11-17 22:35:28 +0000
committerptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2012-11-17 22:35:28 +0000
commit2204995d930d357a0a9ef7148baf9cef26ef5195 (patch)
tree5f6a7c4da23d8bb475225fd05193b5dab6574984 /src
parentbfc56a6cb7aa46c16fb960156a7e389ed743670a (diff)
downloadpyparsing-2204995d930d357a0a9ef7148baf9cef26ef5195.tar.gz
Rename operatorPrecedence to infixNotation; add optional lpar and rpar arguments to infixNotation
git-svn-id: svn://svn.code.sf.net/p/pyparsing/code/trunk@242 9bf210a0-9d2d-494c-87cf-cfb32e7dff7b
Diffstat (limited to 'src')
-rw-r--r--src/pyparsing_py2.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/pyparsing_py2.py b/src/pyparsing_py2.py
index bbe38b8..e831b60 100644
--- a/src/pyparsing_py2.py
+++ b/src/pyparsing_py2.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
@@ -88,7 +88,7 @@ __all__ = [
'punc8bit', 'pythonStyleComment', 'quotedString', 'removeQuotes', 'replaceHTMLEntity',
'replaceWith', 'restOfLine', 'sglQuotedString', 'srange', 'stringEnd',
'stringStart', 'traceParseAction', 'unicodeString', 'upcaseTokens', 'withAttribute',
-'indentedBlock', 'originalTextFor', 'ungroup',
+'indentedBlock', 'originalTextFor', 'ungroup', 'infixNotation',
]
"""
@@ -3490,7 +3490,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
@@ -3513,9 +3513,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:
@@ -3560,6 +3562,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")