MCPcopy Create free account
hub / github.com/AfterShip/clickhouse-sql-parser / wrapError

Method wrapError

parser/parser_common.go:369–405  ·  view source on GitHub ↗
(err error)

Source from the content-addressed store, hash-verified

367}
368
369func (p *Parser) wrapError(err error) error {
370 if err == nil {
371 return nil
372 }
373
374 lineNo := 0
375 column := 0
376
377 for i := 0; i < int(p.Pos()); i++ {
378 if p.lexer.input[i] == '\n' {
379 lineNo++
380 column = 0
381 } else {
382 column++
383 }
384 }
385
386 lines := strings.Split(p.lexer.input, "\n")
387 var buf strings.Builder
388 buf.WriteString(fmt.Sprintf("line %d:%d %s\n", lineNo, column, err.Error()))
389 for i, line := range lines {
390 if i == lineNo {
391 buf.WriteString(line)
392 buf.WriteByte('\n')
393 for j := 0; j < column; j++ {
394 buf.WriteByte(' ')
395 }
396 if p.last() != nil {
397 buf.WriteString(strings.Repeat("^", len(p.last().String)))
398 } else {
399 buf.WriteString("^")
400 }
401 buf.WriteByte('\n')
402 }
403 }
404 return errors.New(buf.String())
405}
406
407func (p *Parser) parseRatioExpr(pos Pos) (*RatioExpr, error) {
408 numerator, err := p.parseNumber(pos)

Callers 1

ParseStmtsMethod · 0.95

Calls 5

PosMethod · 0.95
lastMethod · 0.95
WriteStringMethod · 0.80
WriteByteMethod · 0.80
StringMethod · 0.80

Tested by

no test coverage detected