github.com/cockroachdb/cockroachdb-parser@v0.23.3-0.20240213214944-911057d40c9a/pkg/sql/colexec/execgen/execgen.go (about) 1 // Copyright 2020 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package execgen 12 13 import ( 14 "go/parser" 15 "go/token" 16 "strings" 17 18 "github.com/dave/dst/decorator" 19 ) 20 21 // Generate transforms the string contents of an input execgen template by 22 // processing all supported // execgen annotations. 23 func Generate(inputFileContents string) (string, error) { 24 f, err := decorator.ParseFile(token.NewFileSet(), "", inputFileContents, parser.ParseComments) 25 if err != nil { 26 return "", err 27 } 28 29 // Generate template variants: // execgen:template 30 expandTemplates(f) 31 32 // Inline functions: // execgen:inline 33 inlineFuncs(f) 34 35 // Produce output string. 36 var sb strings.Builder 37 if err := decorator.Fprint(&sb, f); err != nil { 38 panic(err) 39 } 40 return sb.String(), nil 41 }