Multiple colliding references in pyparsings MatchFirst

Viewed 25

I'm building an interpreter for a scripting language. The individual components are working as expected, but when I use them in a delimited list for function arguments the parser resolves the one kind of argument to the wrong type.

Definitions are:

legalChars = alphanums + "-" + "_"
identifier = Word(legalChars)
boolean = CaselessKeyword("TRUE") | CaselessKeyword("FALSE")
number = Word(nums + "." + "-")
lparen = Literal("(").suppress()
rparen = Literal(")").suppress()
constant = number("NUMERIC") | quotedString("STRING") | boolean("BOOL")
operator = (Literal("==") | Literal("!=") | Literal(">") | Literal("<") | Literal(">=") | Literal("<="))("OPERATOR")

condition = Forward()
function = Forward()
attribute = (Word(legalChars) | Combine("[" + Word(legalChars+" ") + "]"))("ATTRIB")
variable = Combine("@" + identifier)("VAR") 
arg = function | condition | constant | attribute | variable
args = delimitedList(arg)
function <<= (identifier("FUNCTOR") + lparen + Optional(args)("ARGS") + rparen)("FUNCTION")
condition = variable + operator + (variable | constant)

The issue happens if I try to have a conditional in the function, like:

iff(@somevar=="Foo")

It won't interpret the conditional. If I try to parse it through arg or args it will interpret it as a variable not a conditional. I've tried the same thing using ^ to separate the values in arg but I get the same result.

1 Answers
Related