File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
internal/engine/postgresql Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -10,9 +10,11 @@ import (
10
10
"strings"
11
11
12
12
nodes "github.com/pganalyze/pg_query_go/v4"
13
+ "github.com/pganalyze/pg_query_go/v4/parser"
13
14
14
15
"github.com/kyleconroy/sqlc/internal/metadata"
15
16
"github.com/kyleconroy/sqlc/internal/sql/ast"
17
+ "github.com/kyleconroy/sqlc/internal/sql/sqlerr"
16
18
)
17
19
18
20
func stringSlice (list * nodes.List ) []string {
@@ -158,7 +160,8 @@ func (p *Parser) Parse(r io.Reader) ([]ast.Statement, error) {
158
160
}
159
161
tree , err := nodes .Parse (string (contents ))
160
162
if err != nil {
161
- return nil , err
163
+ pErr := normalizeErr (err )
164
+ return nil , pErr
162
165
}
163
166
164
167
var stmts []ast.Statement
@@ -184,6 +187,20 @@ func (p *Parser) Parse(r io.Reader) ([]ast.Statement, error) {
184
187
return stmts , nil
185
188
}
186
189
190
+ func normalizeErr (err error ) error {
191
+ pErr := parser.Error {}
192
+ if errors .As (err , & pErr ) {
193
+ sErr := & sqlerr.Error {
194
+ Message : pErr .Message ,
195
+ Err : & pErr ,
196
+ Line : pErr .Lineno ,
197
+ Location : pErr .Cursorpos ,
198
+ }
199
+ return sErr
200
+ }
201
+ return err
202
+ }
203
+
187
204
// https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-COMMENTS
188
205
func (p * Parser ) CommentSyntax () metadata.CommentSyntax {
189
206
return metadata.CommentSyntax {
You can’t perform that action at this time.
0 commit comments