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

Method Parse

internal/engine/postgresql/parse.go:149–181  ·  view source on GitHub ↗
(r io.Reader)

Source from the content-addressed store, hash-verified

147var errSkip = errors.New("skip stmt")
148
149func (p *Parser) Parse(r io.Reader) ([]ast.Statement, error) {
150 contents, err := io.ReadAll(r)
151 if err != nil {
152 return nil, err
153 }
154 tree, err := Parse(string(contents))
155 if err != nil {
156 pErr := normalizeErr(err)
157 return nil, pErr
158 }
159
160 var stmts []ast.Statement
161 for _, raw := range tree.Stmts {
162 n, err := translate(raw.Stmt)
163 if err == errSkip {
164 continue
165 }
166 if err != nil {
167 return nil, err
168 }
169 if n == nil {
170 return nil, fmt.Errorf("unexpected nil node")
171 }
172 stmts = append(stmts, ast.Statement{
173 Raw: &ast.RawStmt{
174 Stmt: n,
175 StmtLocation: int(raw.StmtLocation),
176 StmtLen: int(raw.StmtLen),
177 },
178 })
179 }
180 return stmts, nil
181}
182
183func normalizeErr(err error) error {
184 //TODO: errors.As complains that *parser.Error does not implement error

Callers 2

TestApplyFunction · 0.95
TestUpdateErrorsFunction · 0.95

Implementers 4

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

Calls 3

ParseFunction · 0.85
translateFunction · 0.85
normalizeErrFunction · 0.70

Tested by 2

TestApplyFunction · 0.76
TestUpdateErrorsFunction · 0.76