@@ -26,7 +26,10 @@ func discoverAlias(cursor *parsly.Cursor) string {
2626func expectOperand (cursor * parsly.Cursor ) (node.Node , error ) {
2727 literal , err := TryParseLiteral (cursor )
2828 if literal != nil || err != nil {
29- return literal , err
29+ if err != nil {
30+ return literal , err
31+ }
32+ return applyCollate (cursor , literal )
3033 }
3134
3235 match := cursor .MatchAfterOptional (whitespaceMatcher ,
@@ -64,7 +67,7 @@ func expectOperand(cursor *parsly.Cursor) (node.Node, error) {
6467 if err != nil {
6568 return nil , err
6669 }
67- return & expr.Call {X : selector , Raw : raw , Args : args }, nil
70+ return applyCollate ( cursor , & expr.Call {X : selector , Raw : raw , Args : args })
6871
6972 case exceptKeyword :
7073 return parseStarExpr (cursor , selRaw , selector )
@@ -75,15 +78,15 @@ func expectOperand(cursor *parsly.Cursor) (node.Node, error) {
7578 if match .Code == commentBlock {
7679 comments = match .Text (cursor )
7780 }
78- return expr .NewStar (selector , comments ), nil
81+ return applyCollate ( cursor , expr .NewStar (selector , comments ))
7982 }
80- return selector , nil
83+ return applyCollate ( cursor , selector )
8184 case exceptKeyword :
8285 return nil , cursor .NewError (selectorMatcher )
8386 case nullTokenCode :
84- return expr .NewNullLiteral (match .Text (cursor )), nil
87+ return applyCollate ( cursor , expr .NewNullLiteral (match .Text (cursor )))
8588 case caseBlock :
86- return & expr.Switch {Raw : match .Text (cursor )}, nil
89+ return applyCollate ( cursor , & expr.Switch {Raw : match .Text (cursor )})
8790 case starTokenCode :
8891 selRaw := match .Text (cursor )
8992 selector := expr .NewSelector (selRaw )
@@ -97,7 +100,7 @@ func expectOperand(cursor *parsly.Cursor) (node.Node, error) {
97100 case exceptKeyword :
98101 return parseStarExpr (cursor , selRaw , selector )
99102 }
100- return expr .NewStar (selector , comments ), err
103+ return applyCollate ( cursor , expr .NewStar (selector , comments ))
101104 case parenthesesCode :
102105 raw := match .Text (cursor )
103106 result := expr .NewParenthesis (raw )
@@ -139,13 +142,13 @@ func expectOperand(cursor *parsly.Cursor) (node.Node, error) {
139142 }
140143
141144 }
142- return result , nil
145+ return applyCollate ( cursor , result )
143146 case notOperator :
144147 unary := expr .NewUnary (match .Text (cursor ))
145148 if unary .X , err = expectOperand (cursor ); unary .X == nil || err != nil {
146149 return nil , cursor .NewError (selectorMatcher )
147150 }
148- return unary , nil
151+ return applyCollate ( cursor , unary )
149152 case commentBlock :
150153 return expectOperand (cursor )
151154 case asKeyword , orderByKeyword , onKeyword , fromKeyword , whereKeyword , joinToken , groupByKeyword , havingKeyword , windowTokenCode , nextCode :
@@ -154,6 +157,23 @@ func expectOperand(cursor *parsly.Cursor) (node.Node, error) {
154157 return nil , nil
155158}
156159
160+ func applyCollate (cursor * parsly.Cursor , n node.Node ) (node.Node , error ) {
161+ if n == nil {
162+ return nil , nil
163+ }
164+ pos := cursor .Pos
165+ match := cursor .MatchAfterOptional (whitespaceMatcher , collateKeywordMatcher )
166+ if match .Code != collateKeyword {
167+ cursor .Pos = pos
168+ return n , nil
169+ }
170+ match = cursor .MatchAfterOptional (whitespaceMatcher , identifierMatcher )
171+ if match .Code != identifierCode {
172+ return nil , cursor .NewError (identifierMatcher )
173+ }
174+ return & expr.Collate {X : n , Collation : match .Text (cursor )}, nil
175+ }
176+
157177func parseCallArguments (cursor * parsly.Cursor , raw string , pos int ) ([]node.Node , error ) {
158178 var args []node.Node
159179 if len (raw ) > 0 {
0 commit comments