| 920 | } |
| 921 | |
| 922 | func (t *translator) semExtractExpr(e, partExpr, argExpr ast.Expr, inType super.Type) (sem.Expr, super.Type) { |
| 923 | var partstr string |
| 924 | switch p := partExpr.(type) { |
| 925 | case *ast.IDExpr: |
| 926 | partstr = p.Name |
| 927 | case *ast.Primitive: |
| 928 | if p.Type != "string" { |
| 929 | t.error(partExpr, fmt.Errorf("part must be an identifier or string")) |
| 930 | return badExpr, t.checker.unknown |
| 931 | } else { |
| 932 | partstr = p.Text |
| 933 | } |
| 934 | default: |
| 935 | t.error(partExpr, fmt.Errorf("part must be an identifier or string")) |
| 936 | return badExpr, t.checker.unknown |
| 937 | } |
| 938 | argSemExpr, _ := t.expr(argExpr, inType) |
| 939 | return sem.NewCall(e, |
| 940 | "date_part", |
| 941 | []sem.Expr{ |
| 942 | sem.NewLiteral(partExpr, super.NewString(strings.ToLower(partstr))), |
| 943 | argSemExpr, |
| 944 | }, |
| 945 | ), super.TypeInt64 |
| 946 | } |
| 947 | |
| 948 | func (t *translator) exprs(in []ast.Expr, inType super.Type) ([]sem.Expr, []super.Type) { |
| 949 | exprs := make([]sem.Expr, 0, len(in)) |