Skip to content

Commit 37f9809

Browse files
committed
Added Reserved keyboards; Parse function is ready; catalog for test is ready, tests are on the way
1 parent d7f8a73 commit 37f9809

File tree

4 files changed

+327
-17
lines changed

4 files changed

+327
-17
lines changed

internal/engine/yql/catalog.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package yql
2+
3+
import "github.com/sqlc-dev/sqlc/internal/sql/catalog"
4+
5+
func newTestCatalog() *catalog.Catalog {
6+
return catalog.New("main")
7+
}

internal/engine/yql/convert.go

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,7 @@ func (c *cc) convertJoinSource(n *parser.Join_sourceContext) ast.Node {
226226
jexpr.Jointype = ast.JoinTypeInner
227227
}
228228
if i < len(joinConstraints) {
229-
jc := joinConstraints[i]
230-
231-
if jc != nil {
229+
if jc := joinConstraints[i]; jc != nil {
232230
switch {
233231
case jc.ON() != nil:
234232
if exprCtx := jc.Expr(); exprCtx != nil {
@@ -533,7 +531,6 @@ func (c *cc) convertTypeNameComposite(n parser.IType_name_compositeContext) ast.
533531
return nil
534532
}
535533

536-
// Handle optional type (e.g., Optional<Int32>)
537534
if opt := n.Type_name_optional(); opt != nil {
538535
if typeName := opt.Type_name_or_bind(); typeName != nil {
539536
return &ast.TypeName{
@@ -546,7 +543,6 @@ func (c *cc) convertTypeNameComposite(n parser.IType_name_compositeContext) ast.
546543
}
547544
}
548545

549-
// Handle tuple type (e.g., Tuple<Int32, String>)
550546
if tuple := n.Type_name_tuple(); tuple != nil {
551547
if typeNames := tuple.AllType_name_or_bind(); len(typeNames) > 0 {
552548
var items []ast.Node
@@ -561,7 +557,6 @@ func (c *cc) convertTypeNameComposite(n parser.IType_name_compositeContext) ast.
561557
}
562558
}
563559

564-
// Handle struct type (e.g., Struct<field1: Int32, field2: String>)
565560
if struct_ := n.Type_name_struct(); struct_ != nil {
566561
if structArgs := struct_.AllStruct_arg(); len(structArgs) > 0 {
567562
var items []ast.Node
@@ -577,7 +572,6 @@ func (c *cc) convertTypeNameComposite(n parser.IType_name_compositeContext) ast.
577572
}
578573
}
579574

580-
// Handle variant type (e.g., Variant<Int32, String>)
581575
if variant := n.Type_name_variant(); variant != nil {
582576
if variantArgs := variant.AllVariant_arg(); len(variantArgs) > 0 {
583577
var items []ast.Node
@@ -593,7 +587,6 @@ func (c *cc) convertTypeNameComposite(n parser.IType_name_compositeContext) ast.
593587
}
594588
}
595589

596-
// Handle list type (e.g., List<Int32>)
597590
if list := n.Type_name_list(); list != nil {
598591
if typeName := list.Type_name_or_bind(); typeName != nil {
599592
return &ast.TypeName{
@@ -606,7 +599,6 @@ func (c *cc) convertTypeNameComposite(n parser.IType_name_compositeContext) ast.
606599
}
607600
}
608601

609-
// Handle stream type (e.g., Stream<Int32>)
610602
if stream := n.Type_name_stream(); stream != nil {
611603
if typeName := stream.Type_name_or_bind(); typeName != nil {
612604
return &ast.TypeName{
@@ -619,7 +611,6 @@ func (c *cc) convertTypeNameComposite(n parser.IType_name_compositeContext) ast.
619611
}
620612
}
621613

622-
// Handle flow type (e.g., Flow<Int32>)
623614
if flow := n.Type_name_flow(); flow != nil {
624615
if typeName := flow.Type_name_or_bind(); typeName != nil {
625616
return &ast.TypeName{
@@ -632,7 +623,6 @@ func (c *cc) convertTypeNameComposite(n parser.IType_name_compositeContext) ast.
632623
}
633624
}
634625

635-
// Handle dict type (e.g., Dict<String, Int32>)
636626
if dict := n.Type_name_dict(); dict != nil {
637627
if typeNames := dict.AllType_name_or_bind(); len(typeNames) >= 2 {
638628
return &ast.TypeName{
@@ -648,7 +638,6 @@ func (c *cc) convertTypeNameComposite(n parser.IType_name_compositeContext) ast.
648638
}
649639
}
650640

651-
// Handle set type (e.g., Set<Int32>)
652641
if set := n.Type_name_set(); set != nil {
653642
if typeName := set.Type_name_or_bind(); typeName != nil {
654643
return &ast.TypeName{
@@ -661,7 +650,6 @@ func (c *cc) convertTypeNameComposite(n parser.IType_name_compositeContext) ast.
661650
}
662651
}
663652

664-
// Handle enum type (e.g., Enum<tag1, tag2>)
665653
if enum := n.Type_name_enum(); enum != nil {
666654
if typeTags := enum.AllType_name_tag(); len(typeTags) > 0 {
667655
var items []ast.Node
@@ -676,7 +664,6 @@ func (c *cc) convertTypeNameComposite(n parser.IType_name_compositeContext) ast.
676664
}
677665
}
678666

679-
// Handle resource type (e.g., Resource<tag>)
680667
if resource := n.Type_name_resource(); resource != nil {
681668
if typeTag := resource.Type_name_tag(); typeTag != nil {
682669
// TODO: Handle resource tag
@@ -690,7 +677,6 @@ func (c *cc) convertTypeNameComposite(n parser.IType_name_compositeContext) ast.
690677
}
691678
}
692679

693-
// Handle tagged type (e.g., Tagged<Int32, tag>)
694680
if tagged := n.Type_name_tagged(); tagged != nil {
695681
if typeName := tagged.Type_name_or_bind(); typeName != nil {
696682
if typeTag := tagged.Type_name_tag(); typeTag != nil {
@@ -709,7 +695,6 @@ func (c *cc) convertTypeNameComposite(n parser.IType_name_compositeContext) ast.
709695
}
710696
}
711697

712-
// Handle callable type (e.g., Callable<(Int32, String) -> Bool>)
713698
if callable := n.Type_name_callable(); callable != nil {
714699
// TODO: Handle callable argument list and return type
715700
return &ast.TypeName{

internal/engine/yql/parse.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,31 @@ func (p *Parser) Parse(r io.Reader) ([]ast.Statement, error) {
5454
}
5555
pctx, ok := tree.(*parser.Sql_queryContext)
5656
if !ok {
57-
return nil, fmt.Errorf("expected ParserContext; got %T\n", tree)
57+
return nil, fmt.Errorf("expected ParserContext; got %T\n ", tree)
5858
}
5959
var stmts []ast.Statement
6060
stmtListCtx := pctx.Sql_stmt_list()
6161
if stmtListCtx != nil {
62+
loc := 0
6263
for _, stmt := range stmtListCtx.AllSql_stmt() {
6364
converter := &cc{}
6465
out := converter.convert(stmt)
66+
if _, ok := out.(*ast.TODO); ok {
67+
loc = stmt.GetStop().GetStop() + 2
68+
continue
69+
}
70+
if out != nil {
71+
len := (stmt.GetStop().GetStop() + 1) - loc
72+
stmts = append(stmts, ast.Statement{
73+
Raw: &ast.RawStmt{
74+
Stmt: out,
75+
StmtLocation: loc,
76+
StmtLen: len,
77+
},
78+
})
79+
loc = stmt.GetStop().GetStop() + 2
80+
}
6581
}
6682
}
83+
return stmts, nil
6784
}

0 commit comments

Comments
 (0)