(expr Expr, precedence int)
| 78 | } |
| 79 | |
| 80 | func (p *Parser) parseInfix(expr Expr, precedence int) (Expr, error) { |
| 81 | switch { |
| 82 | case p.matchTokenKind(TokenKindSingleEQ), p.matchTokenKind(TokenKindLT), p.matchTokenKind(TokenKindLE), |
| 83 | p.matchTokenKind(TokenKindGE), p.matchTokenKind(TokenKindGT), |
| 84 | p.matchTokenKind(TokenKindNE), p.matchTokenKind("<>"), |
| 85 | p.matchTokenKind(TokenKindMinus), p.matchTokenKind(TokenKindPlus), p.matchTokenKind(TokenKindMul), |
| 86 | p.matchTokenKind(TokenKindDiv), p.matchTokenKind(TokenKindMod), p.matchTokenKind(TokenKindConcat), |
| 87 | p.matchKeyword(KeywordIn), p.matchKeyword(KeywordLike), |
| 88 | p.matchKeyword(KeywordIlike), p.matchKeyword(KeywordAnd), p.matchKeyword(KeywordOr), |
| 89 | p.matchTokenKind(TokenKindArrow), p.matchTokenKind(TokenKindDoubleEQ): |
| 90 | op := p.last().ToString() |
| 91 | _ = p.lexer.consumeToken() |
| 92 | rightExpr, err := p.parseSubExpr(p.Pos(), precedence) |
| 93 | if err != nil { |
| 94 | return nil, err |
| 95 | } |
| 96 | return &BinaryOperation{ |
| 97 | LeftExpr: expr, |
| 98 | Operation: TokenKind(op), |
| 99 | RightExpr: rightExpr, |
| 100 | }, nil |
| 101 | case p.matchTokenKind(TokenKindDash): |
| 102 | _ = p.lexer.consumeToken() |
| 103 | |
| 104 | if p.matchTokenKind(TokenKindIdent) && p.last().String == "Tuple" { |
| 105 | name, err := p.parseIdent() |
| 106 | if err != nil { |
| 107 | return nil, err |
| 108 | } |
| 109 | if err := p.expectTokenKind(TokenKindLParen); err != nil { |
| 110 | return nil, err |
| 111 | } |
| 112 | // it's a tuple type definition after "::" operator |
| 113 | rightExpr, err := p.parseNestedType(name, p.Pos()) |
| 114 | if err != nil { |
| 115 | return nil, err |
| 116 | } |
| 117 | return &BinaryOperation{ |
| 118 | LeftExpr: expr, |
| 119 | Operation: TokenKindDash, |
| 120 | RightExpr: rightExpr, |
| 121 | }, nil |
| 122 | } |
| 123 | |
| 124 | rightExpr, err := p.parseSubExpr(p.Pos(), precedence) |
| 125 | if err != nil { |
| 126 | return nil, err |
| 127 | } |
| 128 | return &BinaryOperation{ |
| 129 | LeftExpr: expr, |
| 130 | Operation: TokenKindDash, |
| 131 | RightExpr: rightExpr, |
| 132 | }, nil |
| 133 | case p.matchKeyword(KeywordBetween): |
| 134 | return p.parseBetweenClause(expr) |
| 135 | case p.matchKeyword(KeywordGlobal): |
| 136 | _ = p.lexer.consumeToken() |
| 137 | if p.expectKeyword(KeywordIn) != nil { |
no test coverage detected