Skip to content

Commit 6c1e0c8

Browse files
authored
Fix panic while occuring the <EOF> error (#68)
1 parent c838854 commit 6c1e0c8

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ func main() {
5757
parser := clickhouse.NewParser(string(inputBytes))
5858
stmts, err := parser.ParseStatements()
5959
if err != nil {
60-
panic(fmt.Sprintf("parse statements error: %s", err.Error()))
60+
fmt.Printf("parse statements error: %s\n", err.Error())
61+
os.Exit(1)
6162
}
6263
if !options.format { // print AST
6364
bytes, _ := json.MarshalIndent(stmts, "", " ") // nolint

parser/parser_common.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,11 @@ func (p *Parser) wrapError(err error) error {
314314
for j := 0; j < column; j++ {
315315
buf.WriteByte(' ')
316316
}
317-
buf.WriteString(strings.Repeat("^", len(p.lexer.lastToken.String)))
317+
if p.last() != nil {
318+
buf.WriteString(strings.Repeat("^", len(p.last().String)))
319+
} else {
320+
buf.WriteString("^")
321+
}
318322
buf.WriteByte('\n')
319323
}
320324
}

0 commit comments

Comments
 (0)