| 49 | } |
| 50 | |
| 51 | func (p *Parser) Parse(r io.Reader) ([]ast.Statement, error) { |
| 52 | blob, err := io.ReadAll(r) |
| 53 | if err != nil { |
| 54 | return nil, err |
| 55 | } |
| 56 | stmtNodes, _, err := p.pingcap.Parse(string(blob), "", "") |
| 57 | if err != nil { |
| 58 | return nil, normalizeErr(err) |
| 59 | } |
| 60 | var stmts []ast.Statement |
| 61 | for i := range stmtNodes { |
| 62 | converter := &cc{} |
| 63 | out := converter.convert(stmtNodes[i]) |
| 64 | if _, ok := out.(*ast.TODO); ok { |
| 65 | continue |
| 66 | } |
| 67 | |
| 68 | // TODO: Attach the text directly to the ast.Statement node |
| 69 | text := stmtNodes[i].Text() |
| 70 | loc := strings.Index(string(blob), text) |
| 71 | |
| 72 | stmtLen := len(text) |
| 73 | if text[stmtLen-1] == ';' { |
| 74 | stmtLen -= 1 // Subtract one to remove semicolon |
| 75 | } |
| 76 | |
| 77 | stmts = append(stmts, ast.Statement{ |
| 78 | Raw: &ast.RawStmt{ |
| 79 | Stmt: out, |
| 80 | StmtLocation: loc, |
| 81 | StmtLen: stmtLen, |
| 82 | }, |
| 83 | }) |
| 84 | } |
| 85 | return stmts, nil |
| 86 | } |
| 87 | |
| 88 | // https://dev.mysql.com/doc/refman/8.0/en/comments.html |
| 89 | func (p *Parser) CommentSyntax() source.CommentSyntax { |