MCPcopy Index your code
hub / github.com/LissaGreense/GO4SQL / parseCreateCommand

Method parseCreateCommand

parser/parser.go:71–139  ·  view source on GitHub ↗

parseCreateCommand - Return ast.CreateCommand created from tokens and validate the syntax Example of input parsable to the ast.CreateCommand: create table tbl( one TEXT , two INT );

()

Source from the content-addressed store, hash-verified

69// Example of input parsable to the ast.CreateCommand:
70// create table tbl( one TEXT , two INT );
71func (parser *Parser) parseCreateCommand() (ast.Command, error) {
72 // token.CREATE already at current position in parser
73 createCommand := &ast.CreateCommand{Token: parser.currentToken}
74
75 // Skip token.CREATE
76 parser.nextToken()
77
78 err := validateTokenAndSkip(parser, []token.Type{token.TABLE})
79 if err != nil {
80 return nil, err
81 }
82
83 err = validateToken(parser.currentToken.Type, []token.Type{token.IDENT})
84 if err != nil {
85 return nil, err
86 }
87
88 if strings.Contains(parser.currentToken.Literal, ".") {
89 return nil, &IllegalPeriodInIdentParserError{name: parser.currentToken.Literal}
90 }
91 createCommand.Name = ast.Identifier{Token: parser.currentToken}
92
93 // Skip token.IDENT
94 parser.nextToken()
95
96 err = validateTokenAndSkip(parser, []token.Type{token.LPAREN})
97 if err != nil {
98 return nil, err
99 }
100
101 // Begin of inside Paren
102 for parser.currentToken.Type == token.IDENT {
103 err = validateToken(parser.peekToken.Type, []token.Type{token.TEXT, token.INT})
104 if err != nil {
105 return nil, err
106 }
107
108 if strings.Contains(parser.currentToken.Literal, ".") {
109 return nil, &IllegalPeriodInIdentParserError{name: parser.currentToken.Literal}
110 }
111
112 createCommand.ColumnNames = append(createCommand.ColumnNames, parser.currentToken.Literal)
113 createCommand.ColumnTypes = append(createCommand.ColumnTypes, parser.peekToken)
114
115 // Skip token.IDENT
116 parser.nextToken()
117 // Skip token.TEXT or token.INT
118 parser.nextToken()
119
120 if parser.currentToken.Type != token.COMMA {
121 break
122 }
123
124 // Skip token.COMMA
125 parser.nextToken()
126 }
127 // End of inside Paren
128

Callers 1

ParseSequenceMethod · 0.95

Calls 3

nextTokenMethod · 0.95
validateTokenAndSkipFunction · 0.85
validateTokenFunction · 0.85

Tested by

no test coverage detected