Add Function Parsing To Simple Pyparsing Arithmetics Grammar
I have this code: import pyparsing as pp point = pp.Literal('.') number = pp.Combine(pp.Word(pp.nums) + pp.Optional(point + pp.Word(pp.nums))) lpar = pp.Literal(
Solution 1:
In this grammar, a function call is at the same level as a variable reference or numeric literal, so I would add it as part of the definition of atom
:
function_call = Group(ident + lpar + Group(Optional(delimitedList(expr))) + rpar)
atom = number | function_call | ident | pp.Group(lpar + expr + rpar)
Also note the use of delimitedList
in place of expr + ZeroOrMore(comma + expr)
.
Post a Comment for "Add Function Parsing To Simple Pyparsing Arithmetics Grammar"