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

Method getContainExpression

parser/parser.go:844–903  ·  view source on GitHub ↗

getContainExpression - Return ast.ContainExpression created from tokens and validate the syntax

(leftSide token.Token, isAnonymitifier bool)

Source from the content-addressed store, hash-verified

842
843// getContainExpression - Return ast.ContainExpression created from tokens and validate the syntax
844func (parser *Parser) getContainExpression(leftSide token.Token, isAnonymitifier bool) (bool, *ast.ContainExpression, error) {
845 containExpression := &ast.ContainExpression{}
846
847 if isAnonymitifier {
848 return false, nil, &SyntaxError{expecting: []string{token.IDENT}, got: "'" + leftSide.Literal + "'"}
849 }
850
851 containExpression.Left = ast.Identifier{Token: leftSide}
852
853 if parser.currentToken.Type == token.IN {
854 containExpression.Contains = true
855 } else {
856 containExpression.Contains = false
857 }
858
859 // skip IN or NOTIN
860 parser.nextToken()
861
862 err := validateTokenAndSkip(parser, []token.Type{token.LPAREN})
863 if err != nil {
864 return false, nil, err
865 }
866
867 for parser.currentToken.Type == token.IDENT || parser.currentToken.Type == token.LITERAL || parser.currentToken.Type == token.NULL || parser.currentToken.Type == token.APOSTROPHE {
868 startedWithApostrophe := parser.skipIfCurrentTokenIsApostrophe()
869
870 err = validateToken(parser.currentToken.Type, []token.Type{token.IDENT, token.LITERAL, token.NULL})
871 if err != nil {
872 return false, nil, err
873 }
874 currentAnonymitifier := ast.Anonymitifier{Token: parser.currentToken}
875 containExpression.Right = append(containExpression.Right, currentAnonymitifier)
876 // Ignore token.IDENT, token.LITERAL or token.NULL
877 parser.nextToken()
878
879 finishedWithApostrophe := parser.skipIfCurrentTokenIsApostrophe()
880
881 err = validateApostropheWrapping(startedWithApostrophe, finishedWithApostrophe, currentAnonymitifier.GetToken())
882 if err != nil {
883 return false, nil, err
884 }
885
886 if parser.currentToken.Type != token.COMMA {
887 if parser.currentToken.Type != token.RPAREN {
888 return false, nil, &SyntaxError{expecting: []string{token.COMMA, token.RPAREN}, got: string(parser.currentToken.Type)}
889 }
890 break
891 }
892
893 // Ignore token.COMMA
894 parser.nextToken()
895 }
896
897 err = validateTokenAndSkip(parser, []token.Type{token.RPAREN})
898 if err != nil {
899 return false, nil, err
900 }
901

Callers 1

getExpressionMethod · 0.95

Calls 6

nextTokenMethod · 0.95
GetTokenMethod · 0.95
validateTokenAndSkipFunction · 0.85
validateTokenFunction · 0.85

Tested by

no test coverage detected