[Pyparsing] Indefinitely recursive grammar because of unary operation in operatorPrecedence()
Brought to you by:
ptmcg
From: Gustavo N. <me...@gu...> - 2009-07-06 21:29:25
|
Hello, everyone. I'm using the operatorPrecedence() function to define a grammar for boolean expressions and this grammar becomes indefinitely recursive when I add an unary operation (the negation). I'm using it like this: operation = operatorPrecedence( operand, [ (relationals, 2, opAssoc.LEFT), (belongs_to, 2, opAssoc.LEFT), (is_subset, 2, opAssoc.LEFT), (not_, 1, opAssoc.RIGHT), (and_, 2, opAssoc.LEFT), (ex_or, 2, opAssoc.LEFT), (in_or, 2, opAssoc.LEFT), ] ) Because I want to support operations such as: * "pi == 3.1416" (relationals) * "3.1416 > pi" (relationals) * "user in allowed_people" (belongs_to) * "not user in allowed_people" (not_, belongs_to) * "not today_is_sunday" (not_) * "weather:today_will_rain() and weather:current_season == 'summer'" This is, I really want relational and set-specific operations (belongs_to, is_subset) to have a higher precedence than the negation. If I remove the not_ operator, the grammar is not indefinitely recursive anymore. What am I doing wrong? I've extracted the relevant code from my project and I've attached it to this email, so you can reproduce it easily. Thanks in advance! -- Gustavo Narea <xri://=Gustavo>. | Tech blog: =Gustavo/(+blog)/tech ~ About me: =Gustavo/about | |