summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2016-01-01 01:13:22 +0000
committerptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2016-01-01 01:13:22 +0000
commitf0ae045c3d7532f835afc916223d2c0839c53a14 (patch)
tree6593afc0f8d04f7e705c5409cb7cedf9394ba32e
parent5e00415860c69a3221e08350e2b0d167e11a3b15 (diff)
downloadpyparsing-f0ae045c3d7532f835afc916223d2c0839c53a14.tar.gz
More internal expression naming, in internal elements of infixNotation
git-svn-id: svn://svn.code.sf.net/p/pyparsing/code/trunk@312 9bf210a0-9d2d-494c-87cf-cfb32e7dff7b
-rw-r--r--src/pyparsing.py7
-rw-r--r--src/unitTests.py12
2 files changed, 15 insertions, 4 deletions
diff --git a/src/pyparsing.py b/src/pyparsing.py
index da55b0a..d1d5b53 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.8"
-__versionTime__ = "31 Dec 2015 06:02"
+__versionTime__ = "31 Dec 2015 19:10"
__author__ = "Paul McGuire <ptmcg@users.sourceforge.net>"
import string
@@ -3596,11 +3596,12 @@ def infixNotation( baseExpr, opList, lpar=Suppress('('), rpar=Suppress(')') ):
lastExpr = baseExpr | ( lpar + ret + rpar )
for i,operDef in enumerate(opList):
opExpr,arity,rightLeftAssoc,pa = (operDef + (None,))[:4]
+ termName = "%s term" % opExpr if arity < 3 else "%s%s term" % opExpr
if arity == 3:
if opExpr is None or len(opExpr) != 2:
raise ValueError("if numterms=3, opExpr must be a tuple or list of two expressions")
opExpr1, opExpr2 = opExpr
- thisExpr = Forward()#.setName("expr%d" % i)
+ thisExpr = Forward().setName(termName)
if rightLeftAssoc == opAssoc.LEFT:
if arity == 1:
matchExpr = FollowedBy(lastExpr + opExpr) + Group( lastExpr + OneOrMore( opExpr ) )
@@ -3634,7 +3635,7 @@ 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.setName(termName) | lastExpr )
lastExpr = thisExpr
ret <<= lastExpr
return ret
diff --git a/src/unitTests.py b/src/unitTests.py
index ee26d83..ab40888 100644
--- a/src/unitTests.py
+++ b/src/unitTests.py
@@ -2313,7 +2313,7 @@ class SetNameTest(ParseTestCase):
def runTest(self):
from pyparsing import (oneOf,infixNotation,Word,nums,opAssoc,delimitedList,countedArray,
nestedExpr,makeHTMLTags,anyOpenTag,anyCloseTag,commonHTMLEntity,replaceHTMLEntity)
-
+
a = oneOf("a b c")
b = oneOf("d e f")
arith_expr = infixNotation(Word(nums),
@@ -2321,12 +2321,19 @@ class SetNameTest(ParseTestCase):
(oneOf('* /'),2,opAssoc.LEFT),
(oneOf('+ -'),2,opAssoc.LEFT),
])
+ arith_expr2 = infixNotation(Word(nums),
+ [
+ (('?',':'),3,opAssoc.LEFT),
+ ])
tests = [
a,
b,
(a | b),
arith_expr,
+ arith_expr.expr,
+ arith_expr2,
+ arith_expr2.expr,
delimitedList(Word(nums).setName("int")),
countedArray(Word(nums).setName("int")),
nestedExpr(),
@@ -2341,6 +2348,9 @@ class SetNameTest(ParseTestCase):
d | e | f
{a | b | c | d | e | f}
Forward: ...
+ + | - term
+ Forward: ...
+ ?: term
int [, int]...
(len) int...
nested () expression