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

Method Parse

internal/engine/dolphin/parse.go:51–86  ·  view source on GitHub ↗
(r io.Reader)

Source from the content-addressed store, hash-verified

49}
50
51func (p *Parser) Parse(r io.Reader) ([]ast.Statement, error) {
52 blob, err := io.ReadAll(r)
53 if err != nil {
54 return nil, err
55 }
56 stmtNodes, _, err := p.pingcap.Parse(string(blob), "", "")
57 if err != nil {
58 return nil, normalizeErr(err)
59 }
60 var stmts []ast.Statement
61 for i := range stmtNodes {
62 converter := &cc{}
63 out := converter.convert(stmtNodes[i])
64 if _, ok := out.(*ast.TODO); ok {
65 continue
66 }
67
68 // TODO: Attach the text directly to the ast.Statement node
69 text := stmtNodes[i].Text()
70 loc := strings.Index(string(blob), text)
71
72 stmtLen := len(text)
73 if text[stmtLen-1] == ';' {
74 stmtLen -= 1 // Subtract one to remove semicolon
75 }
76
77 stmts = append(stmts, ast.Statement{
78 Raw: &ast.RawStmt{
79 Stmt: out,
80 StmtLocation: loc,
81 StmtLen: stmtLen,
82 },
83 })
84 }
85 return stmts, nil
86}
87
88// https://dev.mysql.com/doc/refman/8.0/en/comments.html
89func (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 4

convertMethod · 0.95
IndexMethod · 0.80
normalizeErrFunction · 0.70
ParseMethod · 0.65

Tested by

no test coverage detected