parseLimitCommand - Return ast.LimitCommand created from tokens and validate the syntax Example of input parsable to the ast.LimitCommand: LIMIT 10
()
| 498 | // Example of input parsable to the ast.LimitCommand: |
| 499 | // LIMIT 10 |
| 500 | func (parser *Parser) parseLimitCommand() (ast.Command, error) { |
| 501 | // token.LIMIT already at current position in parser |
| 502 | limitCommand := &ast.LimitCommand{Token: parser.currentToken} |
| 503 | |
| 504 | // token.LIMIT no longer needed |
| 505 | parser.nextToken() |
| 506 | |
| 507 | err := validateToken(parser.currentToken.Type, []token.Type{token.LITERAL}) |
| 508 | if err != nil { |
| 509 | return nil, err |
| 510 | } |
| 511 | |
| 512 | // convert count number to int |
| 513 | count, err := strconv.Atoi(parser.currentToken.Literal) |
| 514 | if err != nil { |
| 515 | return nil, err |
| 516 | } |
| 517 | |
| 518 | if count < 0 { |
| 519 | return nil, &ArithmeticLessThanZeroParserError{variable: "limit"} |
| 520 | } |
| 521 | |
| 522 | limitCommand.Count = count |
| 523 | |
| 524 | // Skip token.IDENT |
| 525 | parser.nextToken() |
| 526 | |
| 527 | parser.skipIfCurrentTokenIsSemicolon() |
| 528 | |
| 529 | return limitCommand, nil |
| 530 | } |
| 531 | |
| 532 | // parseOffsetCommand - Return ast.OffsetCommand created from tokens and validate the syntax |
| 533 | // |
no test coverage detected