MCPcopy Create free account
hub / github.com/Permify/permify / parseInfixExpression

Method parseInfixExpression

pkg/dsl/parser/parser.go:658–691  ·  view source on GitHub ↗

parseInfixExpression parses an infix expression that has a left operand and an operator followed by a right operand, such as "a or b" or "x and y". It takes the left operand as an argument, constructs an InfixExpression with the current operator and left operand, and parses the right operand with a

(left ast.Expression)

Source from the content-addressed store, hash-verified

656// expression tree.
657// It returns the resulting InfixExpression and any error encountered.
658func (p *Parser) parseInfixExpression(left ast.Expression) (ast.Expression, error) {
659 // Ensure the current token is a valid infix operator before proceeding.
660 if !p.isInfixOperator(p.currentToken.Type) {
661 p.currentError(token.AND, token.OR, token.NOT) // Replace with your actual valid infix token types
662 return nil, p.Error()
663 }
664
665 // Create a new InfixExpression with the left operand and the current operator.
666 expression := &ast.InfixExpression{
667 Op: p.currentToken,
668 Left: left,
669 Operator: ast.Operator(p.currentToken.Literal),
670 }
671
672 // Get the precedence of the current operator and consume the operator token.
673 precedence := p.currentPrecedence()
674 p.next()
675
676 // Parse the right operand with a higher precedence to construct the final expression tree.
677 right, err := p.parseExpression(precedence)
678 if err != nil {
679 return nil, err
680 }
681
682 // Ensure the right operand is not nil.
683 if right == nil {
684 p.currentError(token.IDENT, token.LP) // Replace with your actual valid right operand token types
685 return nil, p.Error()
686 }
687
688 // Set the right operand of the InfixExpression and return it.
689 expression.Right = right
690 return expression, nil
691}
692
693// parseIntegerLiteral parses an integer literal and returns the resulting IntegerLiteral expression.
694func (p *Parser) isInfixOperator(tokenType token.Type) bool {

Callers

nothing calls this directly

Calls 7

isInfixOperatorMethod · 0.95
currentErrorMethod · 0.95
ErrorMethod · 0.95
currentPrecedenceMethod · 0.95
nextMethod · 0.95
parseExpressionMethod · 0.95
OperatorTypeAlias · 0.92

Tested by

no test coverage detected