SQLite

Check-in [8781d7352b]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Another version of the parser with a slightly richer syntax. The ghastly pipe operator is now optional, but is never required. Pipelines cannot be initiated from an arbitrary SELECT unless the arbitrary SELECT is a subquery on the initial FROM.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sql-pipes
Files: files | file ages | folders
SHA3-256: 8781d7352b926129027f73d1fe21df78fcb6d21ab3caeefe0f829437c7c1250b
User & Date: drh 2024-08-26 02:53:31.582
Context
2024-08-26
12:26
Reduce rules added to the grammar. Kinda works, but there are still bugs. (check-in: 3c7a5cc6d0 user: drh tags: sql-pipes)
02:53
Another version of the parser with a slightly richer syntax. The ghastly pipe operator is now optional, but is never required. Pipelines cannot be initiated from an arbitrary SELECT unless the arbitrary SELECT is a subquery on the initial FROM. (check-in: 8781d7352b user: drh tags: sql-pipes)
00:15
Proof-of-concept grammar rules to parse Google-style "pipe" syntax for SQL, without the ghastly "|>" operator. The grammar rules are not connected to working code. They just parse the syntax. Pipelines that begin with an ordinary SELECT statement must have the keyword "INTO" (rather than the "|>" operator) separating the SELECT from the start of the pipeline, to avoid syntactic and semantic ambiguity. (check-in: 2c4bae3e68 user: drh tags: sql-pipes)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/parse.y.
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
%left BITAND BITOR LSHIFT RSHIFT.
%left PLUS MINUS.
%left STAR SLASH REM.
%left CONCAT PTR.
%left COLLATE.
%right BITNOT.
%nonassoc ON FROM.
%nonassoc JOIN_KW.

// An IDENTIFIER can be a generic identifier, or one of several
// keywords.  Any non-standard keyword can also be an identifier.
//
%token_class id  ID|INDEXED.

// And "ids" is an identifer-or-string.







|







292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
%left BITAND BITOR LSHIFT RSHIFT.
%left PLUS MINUS.
%left STAR SLASH REM.
%left CONCAT PTR.
%left COLLATE.
%right BITNOT.
%nonassoc ON FROM.
%nonassoc JOIN_KW JOIN AS.

// An IDENTIFIER can be a generic identifier, or one of several
// keywords.  Any non-standard keyword can also be an identifier.
//
%token_class id  ID|INDEXED.

// And "ids" is an identifer-or-string.
625
626
627
628
629
630
631
632
633
634



635
636
637
638
639
640
641
642
643


644
645

646
647
648
649
650
651
652
}
%endif

//%type pipeline {Select*}
//%destructor pipeline {sqlite3SelectDelete(pParse->db,$$);}

oneselect(A) ::= pipeline.  {A = 0;}
oneselect(A) ::= oneselect INTO pipeline.  {A = 0;}
pipeline ::= FROM seltablist.
pipeline ::= TABLE nm dbnm.



pipeline ::= pipeline pipejoinop nm dbnm as on_using.
pipeline ::= pipeline pipejoinop nm dbnm LP exprlist RP as on_using.
pipeline ::= pipeline pipejoinop LP select RP as on_using.
pipeline ::= pipeline pipejoinop LP seltablist RP as on_using.
pipeline ::= pipeline WHERE expr.
pipeline ::= pipeline AGGREGATE selcollist groupby_opt.
pipeline ::= pipeline SELECT selcollist.
pipeline ::= pipeline ORDER BY nexprlist limit_opt.




%type pipejoinop {int}

pipejoinop(X) ::= JOIN_KW(A) JOIN.
                  {X = sqlite3JoinType(pParse,&A,0,0);  /*X-overwrites-A*/}
pipejoinop(X) ::= JOIN_KW(A) nm(B) JOIN.
                  {X = sqlite3JoinType(pParse,&A,&B,0); /*X-overwrites-A*/}
pipejoinop(X) ::= JOIN_KW(A) nm(B) nm(C) JOIN.
                  {X = sqlite3JoinType(pParse,&A,&B,&C);/*X-overwrites-A*/}








<

|
>
>
>
|
|
|
|
|
|
|
|

>
>


>







625
626
627
628
629
630
631

632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
}
%endif

//%type pipeline {Select*}
//%destructor pipeline {sqlite3SelectDelete(pParse->db,$$);}

oneselect(A) ::= pipeline.  {A = 0;}

pipeline ::= FROM seltablist.
pipeline ::= pipeline pipe pipejoinop nm dbnm as on_using.
pipeline ::= pipeline pipe pipejoinop nm dbnm LP exprlist RP as on_using.
pipeline ::= pipeline pipe pipejoinop LP select RP as on_using.
pipeline ::= pipeline pipe pipejoinop LP seltablist RP as on_using.
pipeline ::= pipeline pipe WHERE expr.
pipeline ::= pipeline pipe AGGREGATE selcollist groupby_opt.
pipeline ::= pipeline pipe SELECT selcollist.
pipeline ::= pipeline pipe ORDER BY nexprlist.
pipeline ::= pipeline pipe LIMIT expr.
pipeline ::= pipeline pipe LIMIT expr OFFSET expr.
pipeline ::= pipeline pipe AS nm.
pipeline ::= pipeline pipe DISTINCT ON nexprlist.

pipe ::= .
pipe ::= PIPE.

%type pipejoinop {int}
pipejoinop(X) ::= JOIN.              { X = JT_INNER; }
pipejoinop(X) ::= JOIN_KW(A) JOIN.
                  {X = sqlite3JoinType(pParse,&A,0,0);  /*X-overwrites-A*/}
pipejoinop(X) ::= JOIN_KW(A) nm(B) JOIN.
                  {X = sqlite3JoinType(pParse,&A,&B,0); /*X-overwrites-A*/}
pipejoinop(X) ::= JOIN_KW(A) nm(B) nm(C) JOIN.
                  {X = sqlite3JoinType(pParse,&A,&B,&C);/*X-overwrites-A*/}

714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
}

// An option "AS <id>" phrase that can follow one of the expressions that
// define the result set, or one of the tables in the FROM clause.
//
%type as {Token}
as(X) ::= AS nm(Y).    {X = Y;}
as(X) ::= ids(X).
as(X) ::= .            {X.n = 0; X.z = 0;}


%type seltablist {SrcList*}
%destructor seltablist {sqlite3SrcListDelete(pParse->db, $$);}
%type stl_prefix {SrcList*}
%destructor stl_prefix {sqlite3SrcListDelete(pParse->db, $$);}
%type from {SrcList*}







|
|







719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
}

// An option "AS <id>" phrase that can follow one of the expressions that
// define the result set, or one of the tables in the FROM clause.
//
%type as {Token}
as(X) ::= AS nm(Y).    {X = Y;}
as(X) ::= ids(X).  [AS]
as(X) ::= .        [AS]{X.n = 0; X.z = 0;}


%type seltablist {SrcList*}
%destructor seltablist {sqlite3SrcListDelete(pParse->db, $$);}
%type stl_prefix {SrcList*}
%destructor stl_prefix {sqlite3SrcListDelete(pParse->db, $$);}
%type from {SrcList*}