diff --git a/parser/parser_table.go b/parser/parser_table.go index a0d81b9..04177a4 100644 --- a/parser/parser_table.go +++ b/parser/parser_table.go @@ -1,6 +1,7 @@ package parser import ( + "errors" "fmt" ) @@ -1454,6 +1455,9 @@ func (p *Parser) parseStmt(pos Pos) (Expr, error) { case p.matchKeyword(KeywordDesc), p.matchKeyword(KeywordDescribe): expr, err = p.parseDescribeStmt(pos) default: + if p.last() == nil { + return nil, errors.New("unexpected end of input") + } return nil, fmt.Errorf("unexpected token: %q", p.last().String) } if err != nil { @@ -1474,7 +1478,9 @@ func (p *Parser) parseStmt(pos Pos) (Expr, error) { func (p *Parser) ParseStmts() ([]Expr, error) { var stmts []Expr for { - _ = p.lexer.consumeToken() + if err := p.lexer.consumeToken(); err != nil { + return nil, p.wrapError(err) + } if p.lexer.isEOF() { break } diff --git a/parser/parser_test.go b/parser/parser_test.go index d6fbab4..b4939e1 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -186,6 +186,7 @@ func TestParser_InvalidSyntax(t *testing.T) { // Invalid ARRAY JOIN types (only ARRAY JOIN, LEFT ARRAY JOIN, and INNER ARRAY JOIN are valid) "SELECT * FROM t RIGHT ARRAY JOIN arr AS a", // RIGHT ARRAY JOIN not supported "SELECT * FROM t FULL ARRAY JOIN arr AS a", // FULL ARRAY JOIN not supported + "00e1d", // invalid number that leaves lastToken nil } for _, sql := range invalidSQLs { parser := NewParser(sql)