github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/parsers/tree/precedence.go (about) 1 // Copyright 2021 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package tree 16 17 type Precedence int 18 19 const ( 20 Syntactic Precedence = iota 21 P1 22 P2 23 P3 24 P4 25 P5 26 P6 27 P7 28 P8 29 P9 30 P10 31 P11 32 P12 33 P13 34 P14 35 P15 36 P16 37 P17 38 ) 39 40 func precedenceFor(in Expr) Precedence { 41 switch node := in.(type) { 42 case *OrExpr: 43 return P16 44 case *XorExpr: 45 return P15 46 case *AndExpr: 47 return P14 48 case *NotExpr: 49 return P13 50 case *RangeCond: 51 return P12 52 case *ComparisonExpr: 53 switch node.Op { 54 case EQUAL, NOT_EQUAL, GREAT_THAN, GREAT_THAN_EQUAL, LESS_THAN, LESS_THAN_EQUAL, LIKE, IN, REG_MATCH: 55 return P11 56 } 57 case *IsNullExpr, *IsNotNullExpr: 58 return P11 59 case *BinaryExpr: 60 switch node.Op { 61 case BIT_OR: 62 return P10 63 case BIT_AND: 64 return P9 65 case LEFT_SHIFT, RIGHT_SHIFT: 66 return P8 67 case PLUS, MINUS: 68 return P7 69 case DIV, MULTI, MOD, INTEGER_DIV: 70 return P6 71 case BIT_XOR: 72 return P5 73 } 74 case *UnaryExpr: 75 switch node.Op { 76 case UNARY_PLUS, UNARY_MINUS: 77 return P4 78 // TODO: 79 case UNARY_TILDE: 80 return P3 81 // TODO: 82 case UNARY_MARK: 83 return P2 84 } 85 case *IntervalExpr: 86 return P1 87 } 88 89 return Syntactic 90 }