@@ -1902,15 +1902,18 @@ enum Parsers {
19021902 while true {
19031903 // If the lhs was a column refernce with no table/schema and we are
19041904 // at an open paren treat as a function call.
1905- if state. is ( of: . openParen) , case let . column( column) = expr, column. schema == nil {
1905+ if state. is ( of: . openParen) ,
1906+ case let . column( columnExpr) = expr,
1907+ case let . column( column) = columnExpr. column,
1908+ columnExpr. schema == nil {
19061909 let args = try parensOrEmpty ( state: & state) { state in
19071910 try commaDelimited ( state: & state) { try Parsers . expr ( state: & $0) }
19081911 }
19091912
19101913 expr = . fn( FunctionExprSyntax (
19111914 id: state. nextId ( ) ,
1912- table: column . table,
1913- name: column. column ,
1915+ table: columnExpr . table,
1916+ name: column,
19141917 args: args ?? [ ] ,
19151918 location: state. location ( from: expr. location) )
19161919 )
@@ -1961,8 +1964,8 @@ enum Parsers {
19611964 switch state. current. kind {
19621965 case . double, . string, . int, . hex, . currentDate, . currentTime, . currentTimestamp, . true , . false :
19631966 return . literal( literal ( state: & state) )
1964- case . symbol:
1965- let column = columnExpr ( state: & state)
1967+ case . symbol, . star :
1968+ let column = try columnExpr ( state: & state, schema : nil , table : nil )
19661969 return . column( column)
19671970 case . questionMark, . colon, . dollarSign, . at:
19681971 return . bindParameter( bindParameter ( state: & state) )
@@ -2054,36 +2057,40 @@ enum Parsers {
20542057
20552058 return . infix( InfixExprSyntax ( id: state. nextId ( ) , lhs: lhs, operator: op, rhs: rhs) )
20562059 }
2057-
2060+
20582061 /// https://www.sqlite.org/syntax/expr.html
2059- static func columnExpr( state: inout ParserState ) -> ColumnExprSyntax {
2060- let first = identifier ( state: & state)
2061-
2062- if state. take ( if: . dot) {
2063- let second = identifier ( state: & state)
2062+ static func columnExpr(
2063+ state: inout ParserState ,
2064+ schema: IdentifierSyntax ? ,
2065+ table: IdentifierSyntax ?
2066+ ) throws -> ColumnExprSyntax {
2067+ switch state. current. kind {
2068+ case . star:
2069+ let star = state. take ( )
2070+ return ColumnExprSyntax (
2071+ id: state. nextId ( ) ,
2072+ schema: schema,
2073+ table: table,
2074+ column: . all( star. location)
2075+ )
2076+ case . symbol:
2077+ let ident = identifier ( state: & state)
20642078
20652079 if state. take ( if: . dot) {
2066- return ColumnExprSyntax (
2067- id: state. nextId ( ) ,
2068- schema: first,
2069- table: second,
2070- column: identifier ( state: & state)
2071- )
2080+ return try columnExpr ( state: & state, schema: table, table: ident)
20722081 } else {
20732082 return ColumnExprSyntax (
20742083 id: state. nextId ( ) ,
2075- schema: nil ,
2076- table: first ,
2077- column: second
2084+ schema: schema ,
2085+ table: table ,
2086+ column: . column ( ident )
20782087 )
20792088 }
2080- } else {
2081- return ColumnExprSyntax (
2082- id: state. nextId ( ) ,
2083- schema: nil ,
2084- table: nil ,
2085- column: first
2086- )
2089+ default :
2090+ throw state. diagnostics. add ( . init(
2091+ " Unexpected token, expected * or an identifier " ,
2092+ at: state. location
2093+ ) )
20872094 }
20882095 }
20892096
0 commit comments