parseJoinCommand - Return ast.JoinCommand created from tokens and validate the syntax Example of input parsable to the ast.JoinCommand: JOIN table on table.one EQUAL table2.one;
()
| 568 | // Example of input parsable to the ast.JoinCommand: |
| 569 | // JOIN table on table.one EQUAL table2.one; |
| 570 | func (parser *Parser) parseJoinCommand() (ast.Command, error) { |
| 571 | // parser has either token.JOIN, token.LEFT, token.RIGHT, token.INNER or token.FULL |
| 572 | var joinCommand *ast.JoinCommand |
| 573 | |
| 574 | if parser.currentToken.Type == token.JOIN { |
| 575 | joinCommand = &ast.JoinCommand{Token: parser.currentToken} |
| 576 | joinCommand.JoinType = token.Token{Type: token.INNER, Literal: token.INNER} |
| 577 | } else { |
| 578 | joinTypeTokenType := parser.currentToken |
| 579 | parser.nextToken() |
| 580 | err := validateToken(parser.currentToken.Type, []token.Type{token.JOIN}) |
| 581 | if err != nil { |
| 582 | return nil, err |
| 583 | } |
| 584 | joinCommand = &ast.JoinCommand{Token: parser.currentToken} |
| 585 | joinCommand.JoinType = joinTypeTokenType |
| 586 | } |
| 587 | |
| 588 | // token.JOIN no longer needed |
| 589 | parser.nextToken() |
| 590 | |
| 591 | err := validateToken(parser.currentToken.Type, []token.Type{token.IDENT}) |
| 592 | if err != nil { |
| 593 | return nil, err |
| 594 | } |
| 595 | |
| 596 | joinCommand.Name = ast.Identifier{Token: parser.currentToken} |
| 597 | parser.nextToken() |
| 598 | |
| 599 | err = validateTokenAndSkip(parser, []token.Type{token.ON}) |
| 600 | if err != nil { |
| 601 | return nil, err |
| 602 | } |
| 603 | |
| 604 | var expressionIsValid bool |
| 605 | expressionIsValid, joinCommand.Expression, err = parser.getExpression() |
| 606 | if err != nil { |
| 607 | return nil, err |
| 608 | } |
| 609 | |
| 610 | if !expressionIsValid { |
| 611 | return nil, &LogicalExpressionParsingError{} |
| 612 | } |
| 613 | |
| 614 | parser.skipIfCurrentTokenIsSemicolon() |
| 615 | |
| 616 | return joinCommand, nil |
| 617 | } |
| 618 | |
| 619 | // parseUpdateCommand - Return ast.parseUpdateCommand created from tokens and validate the syntax |
| 620 | // |
no test coverage detected