Skip to content

Commit 6d08b32

Browse files
committed
Add comment style to parser
1 parent d1f8465 commit 6d08b32

File tree

14 files changed

+69
-6
lines changed

14 files changed

+69
-6
lines changed

internal/cmd/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func (d *dinosqlEngine) Result() golang.Generateable {
209209
}
210210

211211
func parse(e Env, name, dir string, sql config.SQL, combo config.CombinedSettings, parserOpts dinosql.ParserOpts, stderr io.Writer) (golang.Generateable, bool) {
212-
if sql.Engine == config.EngineMySQL && !e.ExperimentalParser {
212+
if sql.Engine == config.EngineMySQL {
213213
// Experimental MySQL support
214214
q, err := mysql.GeneratePkg(name, sql.Schema, sql.Queries, combo)
215215
if err != nil {

internal/compiler/compile.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"regexp"
1010
"strings"
1111

12+
"github.com/kyleconroy/sqlc/internal/metadata"
1213
"github.com/kyleconroy/sqlc/internal/migrations"
1314
"github.com/kyleconroy/sqlc/internal/multierr"
1415
"github.com/kyleconroy/sqlc/internal/sql/ast"
@@ -19,6 +20,7 @@ import (
1920

2021
type Parser interface {
2122
Parse(io.Reader) ([]ast.Statement, error)
23+
CommentSyntax() metadata.CommentSyntax
2224
}
2325

2426
// copied over from gen.go

internal/compiler/engine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func NewEngine(conf config.SQL, combo config.CombinedSettings) *Engine {
2828
case config.EngineXLemon:
2929
e.parser = sqlite.NewParser()
3030
e.catalog = catalog.New("main")
31-
case config.EngineMySQL:
31+
case config.EngineMySQL, config.EngineXDolphin:
3232
e.parser = dolphin.NewParser()
3333
e.catalog = catalog.New("public") // TODO: What is the default database for MySQL?
3434
case config.EnginePostgreSQL:

internal/compiler/parse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func parseQuery(p Parser, c *catalog.Catalog, stmt ast.Node, src string, rewrite
5252
if err := validate.FuncCall(c, raw); err != nil {
5353
return nil, err
5454
}
55-
name, cmd, err := metadata.Parse(strings.TrimSpace(rawSQL), metadata.CommentSyntaxDash)
55+
name, cmd, err := metadata.Parse(strings.TrimSpace(rawSQL), p.CommentSyntax())
5656
if err != nil {
5757
return nil, err
5858
}

internal/config/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ const (
7474
EnginePostgreSQL Engine = "postgresql"
7575

7676
// Experimental engines
77-
EngineXLemon Engine = "_lemon"
77+
EngineXLemon Engine = "_lemon"
78+
EngineXDolphin Engine = "_dolphin"
7879
)
7980

8081
type Config struct {

internal/dolphin/parse.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import (
55
"io/ioutil"
66
"strings"
77

8+
"github.com/davecgh/go-spew/spew"
89
"github.com/pingcap/parser"
910
_ "github.com/pingcap/tidb/types/parser_driver"
1011

12+
"github.com/kyleconroy/sqlc/internal/metadata"
1113
"github.com/kyleconroy/sqlc/internal/sql/ast"
1214
)
1315

@@ -26,6 +28,7 @@ func (p *Parser) Parse(r io.Reader) ([]ast.Statement, error) {
2628
}
2729
stmtNodes, _, err := p.pingcap.Parse(string(blob), "", "")
2830
if err != nil {
31+
spew.Dump(err)
2932
return nil, err
3033
}
3134
var stmts []ast.Statement
@@ -49,3 +52,7 @@ func (p *Parser) Parse(r io.Reader) ([]ast.Statement, error) {
4952
}
5053
return stmts, nil
5154
}
55+
56+
func (p *Parser) CommentSyntax() metadata.CommentSyntax {
57+
return metadata.CommentSyntaxStar
58+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/* name: TooManyFroms :one */
2+
select id, first_name from users from where id = ?;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* name: WrongFunc :one */
2+
select id, first_name from users where id = SQLC_ARGH(target_id);
3+
4+
/* name: InvalidName :one */
5+
select id, first_name from users where id = SQLC_ARG(SQLC_ARG(target_id));
6+
7+
/* name: InvalidVaue :one */
8+
select id, first_name from users where id = SQLC_ARG(?);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/* name: ExtraSelect :one */
2+
select id from users where select id;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* name: MisspelledSelect :one */
2+
selectt id, first_name from users;
3+
4+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CREATE TABLE users (
2+
id integer NOT NULL AUTO_INCREMENT PRIMARY KEY,
3+
first_name varchar(255) NOT NULL,
4+
last_name varchar(255),
5+
age integer NOT NULL,
6+
job_status ENUM('APPLIED', 'PENDING', 'ACCEPTED', 'REJECTED') NOT NULL
7+
) ENGINE=InnoDB;
8+
9+
CREATE TABLE orders (
10+
id integer NOT NULL AUTO_INCREMENT PRIMARY KEY,
11+
price DECIMAL(13, 4) NOT NULL,
12+
user_id integer NOT NULL
13+
) ENGINE=InnoDB;
14+
15+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": "1",
3+
"packages": [
4+
{
5+
"name": "querytest",
6+
"path": "go",
7+
"schema": "schema.sql",
8+
"queries": "query",
9+
"engine": "_dolphin"
10+
}
11+
]
12+
}

internal/postgresql/parse.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import (
77
"io/ioutil"
88
"strings"
99

10-
"github.com/kyleconroy/sqlc/internal/sql/ast"
11-
1210
pg "github.com/lfittl/pg_query_go"
1311
nodes "github.com/lfittl/pg_query_go/nodes"
12+
13+
"github.com/kyleconroy/sqlc/internal/metadata"
14+
"github.com/kyleconroy/sqlc/internal/sql/ast"
1415
)
1516

1617
func stringSlice(list nodes.List) []string {
@@ -202,6 +203,10 @@ func (p *Parser) Parse(r io.Reader) ([]ast.Statement, error) {
202203
return stmts, nil
203204
}
204205

206+
func (p *Parser) CommentSyntax() metadata.CommentSyntax {
207+
return metadata.CommentSyntaxDash
208+
}
209+
205210
func translate(node nodes.Node) (ast.Node, error) {
206211
switch n := node.(type) {
207212

internal/sqlite/parse.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/antlr/antlr4/runtime/Go/antlr"
1010

11+
"github.com/kyleconroy/sqlc/internal/metadata"
1112
"github.com/kyleconroy/sqlc/internal/sql/ast"
1213
"github.com/kyleconroy/sqlc/internal/sqlite/parser"
1314
)
@@ -81,3 +82,7 @@ func (p *Parser) Parse(r io.Reader) ([]ast.Statement, error) {
8182
}
8283
return stmts, nil
8384
}
85+
86+
func (p *Parser) CommentSyntax() metadata.CommentSyntax {
87+
return metadata.CommentSyntaxDash
88+
}

0 commit comments

Comments
 (0)