@@ -949,6 +949,79 @@ impl Parser {
949949 }
950950 Ok ( nodes)
951951 }
952+ fn parse_set_operator ( & mut self , left : Node ) -> BQ2CSTResult < Node > {
953+ let mut operator: Node ;
954+ if self
955+ . get_token ( 0 ) ?
956+ . in_ ( & vec ! [ "INNER" , "FULL" , "LEFT" , "OUTER" ] )
957+ {
958+ let mut method;
959+ if self . get_token ( 0 ) ?. in_ ( & vec ! [ "INNER" , "OUTER" ] ) {
960+ method = self . construct_node ( NodeType :: Keyword ) ?;
961+ } else {
962+ method = self . construct_node ( NodeType :: KeywordSequence ) ?;
963+ self . next_token ( ) ?; // -> OUTER
964+ let outer = self . construct_node ( NodeType :: Keyword ) ?;
965+ method. push_node ( "next_keyword" , outer) ;
966+ }
967+
968+ self . next_token ( ) ?; // -> UNION
969+ operator = self . construct_node ( NodeType :: SetOperator ) ?;
970+ operator. push_node ( "method" , method) ;
971+ } else {
972+ operator = self . construct_node ( NodeType :: SetOperator ) ?;
973+ }
974+ self . next_token ( ) ?; // ALL | DISTINCT
975+ operator. push_node ( "distinct_or_all" , self . construct_node ( NodeType :: Keyword ) ?) ;
976+
977+ if self . get_token ( 1 ) ?. is ( "BY" ) {
978+ self . next_token ( ) ?; // -> BY
979+ let mut by = self . construct_node ( NodeType :: KeywordSequence ) ?;
980+ self . next_token ( ) ?; // -> NAME
981+ let mut name: Node ;
982+ if self . get_token ( 1 ) ?. is ( "ON" ) {
983+ name = self . construct_node ( NodeType :: KeywordSequence ) ?;
984+ self . next_token ( ) ?; // -> ON
985+ let mut on = self . construct_node ( NodeType :: KeywordWithExpr ) ?;
986+ self . next_token ( ) ?; // -> (
987+ let columns = self . parse_grouped_exprs ( false ) ?;
988+
989+ on. push_node ( "expr" , columns) ;
990+ name. push_node ( "next_keyword" , on) ;
991+ } else {
992+ name = self . construct_node ( NodeType :: Keyword ) ?;
993+ }
994+ by. push_node ( "next_keyword" , name) ;
995+ operator. push_node ( "by" , by) ;
996+ } else if self . get_token ( 1 ) ?. in_ ( & vec ! [ "STRICT" , "CORRESPONDING" ] ) {
997+ self . next_token ( ) ?; // -> STRICT | CORRESPONDING
998+ let mut strict_exists = false ;
999+ let mut strict = Node :: empty ( NodeType :: Unknown ) ;
1000+ if self . get_token ( 0 ) ?. is ( "STRICT" ) {
1001+ strict_exists = true ;
1002+ strict = self . construct_node ( NodeType :: KeywordSequence ) ?;
1003+ self . next_token ( ) ?; // -> CORRESPONDING
1004+ }
1005+ let mut corresponding = self . construct_node ( NodeType :: Keyword ) ?;
1006+ if self . get_token ( 1 ) ?. is ( "BY" ) {
1007+ corresponding. node_type = NodeType :: KeywordSequence ;
1008+ self . next_token ( ) ?; // -> BY
1009+ let mut by = self . construct_node ( NodeType :: KeywordWithExpr ) ?;
1010+ self . next_token ( ) ?; // -> (
1011+ by. push_node ( "expr" , self . parse_grouped_exprs ( false ) ?) ;
1012+ corresponding. push_node ( "next_keyword" , by) ;
1013+ }
1014+ if strict_exists {
1015+ strict. push_node ( "next_keyword" , corresponding) ;
1016+ corresponding = strict;
1017+ }
1018+ operator. push_node ( "corresponding" , corresponding) ;
1019+ }
1020+ operator. push_node ( "left" , left) ;
1021+ self . next_token ( ) ?; // DISTINCT -> stmt
1022+ operator. push_node ( "right" , self . parse_select_statement ( false , false ) ?) ;
1023+ Ok ( operator)
1024+ }
9521025 fn parse_statement ( & mut self , semicolon : bool ) -> BQ2CSTResult < Node > {
9531026 let node = match self . get_token ( 0 ) ?. literal . to_uppercase ( ) . as_str ( ) {
9541027 // SELECT
@@ -1588,19 +1661,18 @@ impl Parser {
15881661 ) ) ;
15891662 }
15901663 node. push_node ( "rparen" , self . construct_node ( NodeType :: Symbol ) ?) ;
1591- while self
1592- . get_token ( 1 ) ?
1593- . in_ ( & vec ! [ "UNION" , "INTERSECT" , "EXCEPT" ] )
1594- && root
1664+ while self . get_token ( 1 ) ?. in_ ( & vec ! [
1665+ "UNION" ,
1666+ "INTERSECT" ,
1667+ "EXCEPT" ,
1668+ "INNER" ,
1669+ "FULL" ,
1670+ "LEFT" ,
1671+ "OUTER" ,
1672+ ] ) && root
15951673 {
1596- self . next_token ( ) ?; // stmt -> UNION
1597- let mut operator = self . construct_node ( NodeType :: SetOperator ) ?;
1598- self . next_token ( ) ?; // UNION -> DISTINCT
1599- operator. push_node ( "distinct_or_all" , self . construct_node ( NodeType :: Keyword ) ?) ;
1600- operator. push_node ( "left" , node) ;
1601- self . next_token ( ) ?; // DISTINCT -> stmt
1602- operator. push_node ( "right" , self . parse_select_statement ( false , false ) ?) ;
1603- node = operator;
1674+ self . next_token ( ) ?;
1675+ node = self . parse_set_operator ( node) ?;
16041676 }
16051677 // ORDER BY
16061678 if self . get_token ( 1 ) ?. is ( "ORDER" ) && root {
@@ -1811,19 +1883,18 @@ impl Parser {
18111883 node. push_node ( "limit" , limit) ;
18121884 }
18131885 // UNION
1814- while self
1815- . get_token ( 1 ) ?
1816- . in_ ( & vec ! [ "UNION" , "INTERSECT" , "EXCEPT" ] )
1817- && root
1886+ while self . get_token ( 1 ) ?. in_ ( & vec ! [
1887+ "UNION" ,
1888+ "INTERSECT" ,
1889+ "EXCEPT" ,
1890+ "INNER" ,
1891+ "FULL" ,
1892+ "LEFT" ,
1893+ "OUTER" ,
1894+ ] ) && root
18181895 {
1819- self . next_token ( ) ?; // stmt -> UNION
1820- let mut operator = self . construct_node ( NodeType :: SetOperator ) ?;
1821- self . next_token ( ) ?; // UNION -> DISTINCT
1822- operator. push_node ( "distinct_or_all" , self . construct_node ( NodeType :: Keyword ) ?) ;
1823- operator. push_node ( "left" , node) ;
1824- self . next_token ( ) ?; // DISTINCT -> stmt
1825- operator. push_node ( "right" , self . parse_select_statement ( false , false ) ?) ;
1826- node = operator;
1896+ self . next_token ( ) ?;
1897+ node = self . parse_set_operator ( node) ?;
18271898 }
18281899 // ;
18291900 if self . get_token ( 1 ) ?. is ( ";" ) && semicolon {
0 commit comments