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

Method Parse

internal/engine/clickhouse/parse.go:20–55  ·  view source on GitHub ↗
(r io.Reader)

Source from the content-addressed store, hash-verified

18type Parser struct{}
19
20func (p *Parser) Parse(r io.Reader) ([]ast.Statement, error) {
21 blob, err := io.ReadAll(r)
22 if err != nil {
23 return nil, err
24 }
25
26 ctx := context.Background()
27 stmtNodes, err := parser.Parse(ctx, bytes.NewReader(blob))
28 if err != nil {
29 return nil, err
30 }
31
32 var stmts []ast.Statement
33 for _, stmt := range stmtNodes {
34 converter := &cc{}
35 out := converter.convert(stmt)
36 if _, ok := out.(*ast.TODO); ok {
37 continue
38 }
39
40 // Get position information from the statement
41 pos := stmt.Pos()
42 end := stmt.End()
43 stmtLen := end.Offset - pos.Offset
44
45 stmts = append(stmts, ast.Statement{
46 Raw: &ast.RawStmt{
47 Stmt: out,
48 StmtLocation: pos.Offset,
49 StmtLen: stmtLen,
50 },
51 })
52 }
53
54 return stmts, nil
55}
56
57// https://clickhouse.com/docs/en/sql-reference/syntax#comments
58func (p *Parser) CommentSyntax() source.CommentSyntax {

Callers

nothing calls this directly

Implementers 4

Parserinternal/engine/postgresql/parse.go
Parserinternal/engine/dolphin/parse.go
Parserinternal/engine/clickhouse/parse.go
Parserinternal/engine/sqlite/parse.go

Calls 3

convertMethod · 0.95
ParseMethod · 0.65
PosMethod · 0.65

Tested by

no test coverage detected