parsing an Excel formula with the re module

John Machin sjmachin at lexicon.net
Fri Jan 15 08:23:23 CET 2010


On Jan 15, 3:41 pm, Paul McGuire <pt... at austin.rr.com> wrote:
> 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.



More information about the Python-list mailing list