parseOffsetCommand - Return ast.OffsetCommand created from tokens and validate the syntax Example of input parsable to the ast.LimitCommand: OFFSET 10
()
| 534 | // Example of input parsable to the ast.LimitCommand: |
| 535 | // OFFSET 10 |
| 536 | func (parser *Parser) parseOffsetCommand() (ast.Command, error) { |
| 537 | // token.OFFSET already at current position in parser |
| 538 | offsetCommand := &ast.OffsetCommand{Token: parser.currentToken} |
| 539 | |
| 540 | // token.OFFSET no longer needed |
| 541 | parser.nextToken() |
| 542 | |
| 543 | err := validateToken(parser.currentToken.Type, []token.Type{token.LITERAL}) |
| 544 | if err != nil { |
| 545 | return nil, err |
| 546 | } |
| 547 | |
| 548 | count, err := strconv.Atoi(parser.currentToken.Literal) |
| 549 | if err != nil { |
| 550 | return nil, err |
| 551 | } |
| 552 | if count < 0 { |
| 553 | return nil, &ArithmeticLessThanZeroParserError{variable: "offset"} |
| 554 | } |
| 555 | |
| 556 | offsetCommand.Count = count |
| 557 | |
| 558 | // Skip token.IDENT |
| 559 | parser.nextToken() |
| 560 | |
| 561 | parser.skipIfCurrentTokenIsSemicolon() |
| 562 | |
| 563 | return offsetCommand, nil |
| 564 | } |
| 565 | |
| 566 | // parseJoinCommand - Return ast.JoinCommand created from tokens and validate the syntax |
| 567 | // |
no test coverage detected