diff options
author | ptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b> | 2016-08-09 21:50:19 +0000 |
---|---|---|
committer | ptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b> | 2016-08-09 21:50:19 +0000 |
commit | 0b19bb71ba5a4afa84e673a8239935426fa0db23 (patch) | |
tree | e9abae9c616fdfdfebd9a8a0931d8f21824f30d2 /trunk/src/examples/excelExpr.py | |
parent | b2c3ade75384efe76b8774b607e17fe98fab92ef (diff) | |
download | pyparsing_2.1.6.tar.gz |
Remove incorrect tag directorypyparsing_2.1.6
git-svn-id: svn://svn.code.sf.net/p/pyparsing/code/tags/pyparsing_2.1.6@405 9bf210a0-9d2d-494c-87cf-cfb32e7dff7b
Diffstat (limited to 'trunk/src/examples/excelExpr.py')
-rw-r--r-- | trunk/src/examples/excelExpr.py | 68 |
1 files changed, 0 insertions, 68 deletions
diff --git a/trunk/src/examples/excelExpr.py b/trunk/src/examples/excelExpr.py deleted file mode 100644 index 2700100..0000000 --- a/trunk/src/examples/excelExpr.py +++ /dev/null @@ -1,68 +0,0 @@ -# excelExpr.py
-#
-# Copyright 2010, Paul McGuire
-#
-# A partial implementation of a parser of Excel formula expressions.
-#
-from pyparsing import (CaselessKeyword, Suppress, Word, alphas,
- alphanums, nums, Optional, Group, oneOf, Forward, Regex,
- infixNotation, opAssoc, dblQuotedString, delimitedList,
- Combine, Literal, QuotedString, ParserElement)
-ParserElement.enablePackrat()
-
-EQ,EXCL,LPAR,RPAR,COLON,COMMA = map(Suppress, '=!():,')
-EXCL, DOLLAR = map(Literal,"!$")
-sheetRef = Word(alphas, alphanums) | QuotedString("'",escQuote="''")
-colRef = Optional(DOLLAR) + Word(alphas,max=2)
-rowRef = Optional(DOLLAR) + Word(nums)
-cellRef = Combine(Group(Optional(sheetRef + EXCL)("sheet") + colRef("col") +
- rowRef("row")))
-
-cellRange = (Group(cellRef("start") + COLON + cellRef("end"))("range")
- | cellRef | Word(alphas,alphanums))
-
-expr = Forward()
-
-COMPARISON_OP = oneOf("< = > >= <= != <>")
-condExpr = expr + COMPARISON_OP + expr
-
-ifFunc = (CaselessKeyword("if") +
- LPAR +
- Group(condExpr)("condition") +
- COMMA + Group(expr)("if_true") +
- COMMA + Group(expr)("if_false") + RPAR)
-
-statFunc = lambda name : Group(CaselessKeyword(name) + Group(LPAR + delimitedList(expr) + RPAR))
-sumFunc = statFunc("sum")
-minFunc = statFunc("min")
-maxFunc = statFunc("max")
-aveFunc = statFunc("ave")
-funcCall = ifFunc | sumFunc | minFunc | maxFunc | aveFunc
-
-multOp = oneOf("* /")
-addOp = oneOf("+ -")
-numericLiteral = Regex(r"\-?\d+(\.\d+)?")
-operand = numericLiteral | funcCall | cellRange | cellRef
-arithExpr = infixNotation(operand,
- [
- (multOp, 2, opAssoc.LEFT),
- (addOp, 2, opAssoc.LEFT),
- ])
-
-textOperand = dblQuotedString | cellRef
-textExpr = infixNotation(textOperand,
- [
- ('&', 2, opAssoc.LEFT),
- ])
-
-expr << (arithExpr | textExpr)
-
-
-(EQ + expr).runTests("""\
- =3*A7+5"
- =3*Sheet1!$A$7+5"
- =3*'Sheet 1'!$A$7+5"
- =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))
-""")
\ No newline at end of file |