MCPcopy
hub / github.com/sqlc-dev/sqlc / parse

Function parse

internal/cmd/generate.go:296–334  ·  view source on GitHub ↗
(ctx context.Context, name, dir string, sql config.SQL, combo config.CombinedSettings, parserOpts opts.Parser, stderr io.Writer)

Source from the content-addressed store, hash-verified

294}
295
296func parse(ctx context.Context, name, dir string, sql config.SQL, combo config.CombinedSettings, parserOpts opts.Parser, stderr io.Writer) (*compiler.Result, bool) {
297 defer trace.StartRegion(ctx, "parse").End()
298 c, err := compiler.NewCompiler(sql, combo, parserOpts)
299 defer func() {
300 if c != nil {
301 c.Close(ctx)
302 }
303 }()
304 if err != nil {
305 fmt.Fprintf(stderr, "error creating compiler: %s\n", err)
306 return nil, true
307 }
308 if err := c.ParseCatalog(sql.Schema); err != nil {
309 fmt.Fprintf(stderr, "# package %s\n", name)
310 if parserErr, ok := err.(*multierr.Error); ok {
311 for _, fileErr := range parserErr.Errs() {
312 printFileErr(stderr, dir, fileErr)
313 }
314 } else {
315 fmt.Fprintf(stderr, "error parsing schema: %s\n", err)
316 }
317 return nil, true
318 }
319 if parserOpts.Debug.DumpCatalog {
320 debug.Dump(c.Catalog())
321 }
322 if err := c.ParseQueries(sql.Queries, parserOpts); err != nil {
323 fmt.Fprintf(stderr, "# package %s\n", name)
324 if parserErr, ok := err.(*multierr.Error); ok {
325 for _, fileErr := range parserErr.Errs() {
326 printFileErr(stderr, dir, fileErr)
327 }
328 } else {
329 fmt.Fprintf(stderr, "error parsing queries: %s\n", err)
330 }
331 return nil, true
332 }
333 return c.Result(), false
334}
335
336func codegen(ctx context.Context, combo config.CombinedSettings, sql OutputPair, result *compiler.Result) (string, *plugin.GenerateResponse, error) {
337 defer trace.StartRegion(ctx, "codegen").End()

Callers 2

processQuerySetsFunction · 0.85
checkSQLMethod · 0.85

Calls 9

CloseMethod · 0.95
ParseCatalogMethod · 0.95
CatalogMethod · 0.95
ParseQueriesMethod · 0.95
ResultMethod · 0.95
NewCompilerFunction · 0.92
DumpFunction · 0.92
printFileErrFunction · 0.85
ErrsMethod · 0.80

Tested by

no test coverage detected