def ExpressionWithoutLoopParser(input): expr1 = Parser.leftAssociativeOperatorParser( TermParser, [TokenType.PLUS, TokenType.MINUS], TermParser, lambda left, op, right: Sum.withValues(left, op, right)) expr2 = Parser.leftAssociativeOperatorParser( expr1, [TokenType.RELATION, TokenType.OPEN_ANGLE, TokenType.CLOSE_ANGLE], expr1, lambda left, op, right: Relation.withValues(left, op, right)) expr3 = Parser.leftAssociativeOperatorParser( expr2, [TokenType.AND], expr2, lambda left, op, right: And.withValues(left, op, right)) return Parser.leftAssociativeOperatorParser( expr3, [TokenType.OR], expr3, lambda left, op, right: Or.withValues(left, op, right))(input)
def UnitParser(input): minusOperator = Parser.allOf(Parser.terminal( TokenType.MINUS, createNode=Operator.withValue), Parser.doAssert(AtomParser, "atom"), createNode=MinusOperator.withValues, name="minus") atom2 = Parser.oneOf(minusOperator, AtomParser, name="atom2") return Parser.leftAssociativeOperatorParser( atom2, [TokenType.DOT], Parser.doAssert(atom2, "atom"), createNode=lambda left, op, right: Access.withValues(left, op, right), name="unit")(input)
def FactorParser(input): powerFactor = Parser.leftAssociativeOperatorParser( UnitParser, [TokenType.DOUBLE_ASTERISK], UnitParser, lambda left, op, right: Power.withValues(left, op, right), name="power operator" ) notOperator = Parser.allOf( Parser.terminal(TokenType.NOT, Operator.withValue), powerFactor, createNode=NotOperator.withValues, name="not" ) return Parser.oneOf( notOperator, powerFactor, name="factor" )(input)