parsing an Excel formula with the re module

J

John Machin

I never represented that this parser would handle any and all Excel
formulas!
 But I should hope the basic structure of a pyparsing
solution might help the OP add some of the other features you cited,
if necessary. It's actually pretty common to take an incremental
approach in making such a parser, and so here are some of the changes
that you would need to make based on the deficiencies you pointed out:

functions can have a variable number of arguments, of any kind of
expression
- statFunc = lambda name : CaselessKeyword(name) + LPAR + delimitedList
(expr) + RPAR

sheet name could also be a quoted string
- sheetRef = Word(alphas, alphanums) | QuotedString("'",escQuote="''")

add boolean literal support
- boolLiteral = oneOf("TRUE FALSE")
- operand = numericLiteral | funcCall | boolLiteral | cellRange |
cellRef

or a string literal ... you seem to have ignored the significant point
that the binary operators don't have narrow type requirements of their
args ("""2.3 & 4.5 produces text "2.34.5", while "2.3" + "4.5"
produces number 6.8"""); your attempt to enforce particular types for
args at compile-time is erroneous OVER-engineering.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,110
Latest member
OdetteGabb
Top