| 18 | type Parser struct{} |
| 19 | |
| 20 | func (p *Parser) Parse(r io.Reader) ([]ast.Statement, error) { |
| 21 | blob, err := io.ReadAll(r) |
| 22 | if err != nil { |
| 23 | return nil, err |
| 24 | } |
| 25 | |
| 26 | ctx := context.Background() |
| 27 | stmtNodes, err := parser.Parse(ctx, bytes.NewReader(blob)) |
| 28 | if err != nil { |
| 29 | return nil, err |
| 30 | } |
| 31 | |
| 32 | var stmts []ast.Statement |
| 33 | for _, stmt := range stmtNodes { |
| 34 | converter := &cc{} |
| 35 | out := converter.convert(stmt) |
| 36 | if _, ok := out.(*ast.TODO); ok { |
| 37 | continue |
| 38 | } |
| 39 | |
| 40 | // Get position information from the statement |
| 41 | pos := stmt.Pos() |
| 42 | end := stmt.End() |
| 43 | stmtLen := end.Offset - pos.Offset |
| 44 | |
| 45 | stmts = append(stmts, ast.Statement{ |
| 46 | Raw: &ast.RawStmt{ |
| 47 | Stmt: out, |
| 48 | StmtLocation: pos.Offset, |
| 49 | StmtLen: stmtLen, |
| 50 | }, |
| 51 | }) |
| 52 | } |
| 53 | |
| 54 | return stmts, nil |
| 55 | } |
| 56 | |
| 57 | // https://clickhouse.com/docs/en/sql-reference/syntax#comments |
| 58 | func (p *Parser) CommentSyntax() source.CommentSyntax { |