unnest traverses down the left-hand side of the parse graph until it encounters the first compound parse node or the first leaf in the parse graph.
(tree antlr.ParseTree)
| 1022 | // unnest traverses down the left-hand side of the parse graph until it encounters the first compound |
| 1023 | // parse node or the first leaf in the parse graph. |
| 1024 | func unnest(tree antlr.ParseTree) antlr.ParseTree { |
| 1025 | for tree != nil { |
| 1026 | switch t := tree.(type) { |
| 1027 | case *gen.ExprContext: |
| 1028 | // conditionalOr op='?' conditionalOr : expr |
| 1029 | if t.GetOp() != nil { |
| 1030 | return t |
| 1031 | } |
| 1032 | // conditionalOr |
| 1033 | tree = t.GetE() |
| 1034 | case *gen.ConditionalOrContext: |
| 1035 | // conditionalAnd (ops=|| conditionalAnd)* |
| 1036 | if t.GetOps() != nil && len(t.GetOps()) > 0 { |
| 1037 | return t |
| 1038 | } |
| 1039 | // conditionalAnd |
| 1040 | tree = t.GetE() |
| 1041 | case *gen.ConditionalAndContext: |
| 1042 | // relation (ops=&& relation)* |
| 1043 | if t.GetOps() != nil && len(t.GetOps()) > 0 { |
| 1044 | return t |
| 1045 | } |
| 1046 | // relation |
| 1047 | tree = t.GetE() |
| 1048 | case *gen.RelationContext: |
| 1049 | // relation op relation |
| 1050 | if t.GetOp() != nil { |
| 1051 | return t |
| 1052 | } |
| 1053 | // calc |
| 1054 | tree = t.Calc() |
| 1055 | case *gen.CalcContext: |
| 1056 | // calc op calc |
| 1057 | if t.GetOp() != nil { |
| 1058 | return t |
| 1059 | } |
| 1060 | // unary |
| 1061 | tree = t.Unary() |
| 1062 | case *gen.MemberExprContext: |
| 1063 | // member expands to one of: primary, select, index, or create message |
| 1064 | tree = t.Member() |
| 1065 | case *gen.PrimaryExprContext: |
| 1066 | // primary expands to one of identifier, nested, create list, create struct, literal |
| 1067 | tree = t.Primary() |
| 1068 | case *gen.NestedContext: |
| 1069 | // contains a nested 'expr' |
| 1070 | tree = t.GetE() |
| 1071 | case *gen.ConstantLiteralContext: |
| 1072 | // expands to a primitive literal |
| 1073 | tree = t.Literal() |
| 1074 | default: |
| 1075 | return t |
| 1076 | } |
| 1077 | } |
| 1078 | return tree |
| 1079 | } |
| 1080 | |
| 1081 | var ( |