Skip to content

Commit 8414eb8

Browse files
committed
Enhance comment parsing to support multiline comments in plain.rs
1 parent 7de6136 commit 8414eb8

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

src/format/plain.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ impl PlainHandler {
2323
) -> Result<()> {
2424
let mut writer = BufWriter::with_capacity(65536, writer);
2525
let mut is_data = false;
26+
let mut comment_buf: Option<String> = None;
2627

2728
// If we have initial bytes, chain them with the reader
2829
let combined = std::io::Cursor::new(initial_bytes.to_vec()).chain(reader);
@@ -50,7 +51,30 @@ impl PlainHandler {
5051
continue;
5152
}
5253

53-
// Try to parse as comment
54+
// Handle multiline COMMENT accumulation
55+
if let Some(ref mut buf) = comment_buf {
56+
buf.push('\n');
57+
buf.push_str(&line);
58+
if line.ends_with("';") {
59+
let full_comment = buf.clone();
60+
comment_buf = None;
61+
self.processor.parse_comment(&full_comment);
62+
writer.write_all(full_comment.as_bytes())?;
63+
writer.write_all(b"\n")?;
64+
}
65+
continue;
66+
}
67+
68+
// Detect start of a multiline COMMENT ON COLUMN/TABLE with 'anon:
69+
if (line.starts_with("COMMENT ON COLUMN ") || line.starts_with("COMMENT ON TABLE "))
70+
&& line.contains("'anon: ")
71+
&& !line.ends_with("';")
72+
{
73+
comment_buf = Some(line);
74+
continue;
75+
}
76+
77+
// Try to parse as single-line comment
5478
self.processor.parse_comment(&line);
5579

5680
// Try to parse as COPY statement

0 commit comments

Comments
 (0)