MCPcopy Create free account
hub / github.com/brimdata/super / semExtractExpr

Method semExtractExpr

compiler/semantic/expr.go:922–946  ·  view source on GitHub ↗
(e, partExpr, argExpr ast.Expr, inType super.Type)

Source from the content-addressed store, hash-verified

920}
921
922func (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
948func (t *translator) exprs(in []ast.Expr, inType super.Type) ([]sem.Expr, []super.Type) {
949 exprs := make([]sem.Expr, 0, len(in))

Callers 1

exprMethod · 0.95

Calls 5

exprMethod · 0.95
NewCallFunction · 0.92
NewLiteralFunction · 0.92
NewStringFunction · 0.92
errorMethod · 0.45

Tested by

no test coverage detected