-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstruct.go
More file actions
40 lines (38 loc) · 1.14 KB
/
Copy pathstruct.go
File metadata and controls
40 lines (38 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package sqlparser
import (
"github.com/viant/parsly"
"github.com/viant/sqlparser/node"
"github.com/viant/sqlparser/query"
)
// STRUCT fields are expressions with optional AS names. Named fields reuse
// query.Item so serialization, traversal and transformations retain the name.
func parseStructArguments(cursor *parsly.Cursor) ([]node.Node, error) {
var args []node.Node
skipExpressionSpace(cursor)
if cursor.Pos == len(cursor.Input) {
return args, nil
}
for {
field, err := expectExpression(cursor)
if err != nil {
return nil, err
}
skipExpressionSpace(cursor)
if cursor.MatchOne(selectAsKeywordMatcher).Code == asKeyword {
skipExpressionSpace(cursor)
alias := cursor.MatchOne(aliasIdentifierMatcher)
if alias.Code != identifierCode || !(aliasIdentifier{}).boundary(cursor) {
return nil, cursor.NewError(aliasIdentifierMatcher)
}
field = &query.Item{Expr: field, Alias: alias.Text(cursor)}
}
args = append(args, field)
skipExpressionSpace(cursor)
if cursor.Pos == len(cursor.Input) {
return args, nil
}
if cursor.MatchOne(nextMatcher).Code != nextCode {
return nil, cursor.NewError(nextMatcher)
}
}
}