From 260d2bd117abab2f141184bc7a7f5b4df3f2f672 Mon Sep 17 00:00:00 2001 From: ptmcg Date: Fri, 19 Aug 2016 14:34:24 +0000 Subject: Upgrade to use pyparsing_common for numbers git-svn-id: svn://svn.code.sf.net/p/pyparsing/code/trunk@427 9bf210a0-9d2d-494c-87cf-cfb32e7dff7b --- src/examples/excelExpr.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/examples/excelExpr.py b/src/examples/excelExpr.py index b98115e..7ce8db2 100644 --- a/src/examples/excelExpr.py +++ b/src/examples/excelExpr.py @@ -7,10 +7,10 @@ from pyparsing import (CaselessKeyword, Suppress, Word, alphas, alphanums, nums, Optional, Group, oneOf, Forward, Regex, infixNotation, opAssoc, dblQuotedString, delimitedList, - Combine, Literal, QuotedString, ParserElement) + Combine, Literal, QuotedString, ParserElement, pyparsing_common) ParserElement.enablePackrat() -EQ,EXCL,LPAR,RPAR,COLON,COMMA = map(Suppress, '=!():,') +EQ,LPAR,RPAR,COLON,COMMA = map(Suppress, '=():,') EXCL, DOLLAR = map(Literal,"!$") sheetRef = Word(alphas, alphanums) | QuotedString("'",escQuote="''") colRef = Optional(DOLLAR) + Word(alphas,max=2) @@ -26,7 +26,7 @@ expr = Forward() COMPARISON_OP = oneOf("< = > >= <= != <>") condExpr = expr + COMPARISON_OP + expr -ifFunc = (CaselessKeyword("if") + +ifFunc = (CaselessKeyword("if") - LPAR + Group(condExpr)("condition") + COMMA + Group(expr)("if_true") + @@ -41,7 +41,7 @@ funcCall = ifFunc | sumFunc | minFunc | maxFunc | aveFunc multOp = oneOf("* /") addOp = oneOf("+ -") -numericLiteral = Regex(r"\-?\d+(\.\d+)?") +numericLiteral = pyparsing_common.number operand = numericLiteral | funcCall | cellRange | cellRef arithExpr = infixNotation(operand, [ @@ -65,4 +65,5 @@ expr << (arithExpr | textExpr) =3*'O''Reilly''s sheet'!$A$7+5 =if(Sum(A1:A25)>42,Min(B1:B25),if(Sum(C1:C25)>3.14, (Min(C1:C25)+3)*18,Max(B1:B25))) =sum(a1:a25,10,min(b1,c2,d3)) + =if("T"&a2="TTime", "Ready", "Not ready") """) \ No newline at end of file -- cgit v1.2.1