11package sqlparser
22
33import (
4+ "fmt"
45 "github.com/viant/parsly"
56 "github.com/viant/sqlparser/schema"
67 "strings"
@@ -16,13 +17,18 @@ func ParseRegisterType(SQL string) (*schema.Register, error) {
1617}
1718
1819func parseRegisterType (cursor * parsly.Cursor , destination * schema.Register ) error {
19- match := cursor .MatchAfterOptional (whitespaceMatcher , registerType )
20- if match .Code != registerTypeKeyword {
21- return cursor .NewError (registerType )
20+ match := cursor .MatchAfterOptional (whitespaceMatcher , registerKeywordMatcher )
21+ if match .Code != registerKeyword {
22+ return cursor .NewError (registerKeywordMatcher )
2223 }
2324 if match = cursor .MatchAfterOptional (whitespaceMatcher , globalMatcher ); match .Code == globalKeyword {
2425 destination .Global = true
2526 }
27+
28+ match = cursor .MatchAfterOptional (whitespaceMatcher , typeKeywordMatcher )
29+ if match .Code != typeKeyword {
30+ return cursor .NewError (typeKeywordMatcher )
31+ }
2632 match = cursor .MatchAfterOptional (whitespaceMatcher , selectorMatcher )
2733 if match .Code != selectorTokenCode {
2834 return cursor .NewError (selectorMatcher )
@@ -37,23 +43,41 @@ func parseRegisterType(cursor *parsly.Cursor, destination *schema.Register) erro
3743}
3844
3945// ParseRegisterSet parses register set
40- func ParseRegisterSet (SQL string ) (* schema.Register , error ) {
41- result := & schema.Register {}
46+ func ParseRegisterSet (SQL string ) (* schema.RegisterSet , error ) {
47+ result := & schema.RegisterSet {}
4248 SQL = removeSQLComments (SQL )
4349 cursor := parsly .NewCursor ("" , []byte (SQL ), 0 )
4450 err := parseRegisterSet (cursor , result )
4551 return result , err
4652}
4753
48- // TODO create parse register object
49- func parseRegisterSet (cursor * parsly.Cursor , destination * schema.Register ) error {
50- match := cursor .MatchAfterOptional (whitespaceMatcher , registerSet )
51- if match .Code != registerSetKeyword {
52- return cursor .NewError (registerSet )
54+ func parseRegisterSet (cursor * parsly.Cursor , destination * schema.RegisterSet ) error {
55+ match := cursor .MatchAfterOptional (whitespaceMatcher , registerKeywordMatcher )
56+ if match .Code != registerKeyword {
57+ return cursor .NewError (registerKeywordMatcher )
5358 }
5459 if match = cursor .MatchAfterOptional (whitespaceMatcher , globalMatcher ); match .Code == globalKeyword {
5560 destination .Global = true
5661 }
62+ match = cursor .MatchAfterOptional (whitespaceMatcher , setKeywordMatcher )
63+ if match .Code != setKeyword {
64+ return cursor .NewError (setKeywordMatcher )
65+ }
66+
67+ match = cursor .MatchAfterOptional (whitespaceMatcher , ttlKeywordMatcher )
68+ if match .Code == ttlKeyword {
69+ match = cursor .MatchAfterOptional (whitespaceMatcher , intLiteralMatcher )
70+ if match .Code != intLiteralMatcher .Code {
71+ return cursor .NewError (setKeywordMatcher )
72+ }
73+
74+ ttl64 , err := match .Int (cursor )
75+ if err != nil {
76+ return fmt .Errorf ("parseregisterset unable to get int value due to: %w" , err )
77+ }
78+ destination .TTL = int (ttl64 )
79+ }
80+
5781 match = cursor .MatchAfterOptional (whitespaceMatcher , selectorMatcher )
5882 if match .Code != selectorTokenCode {
5983 return cursor .NewError (selectorMatcher )
0 commit comments