Skip to content

Commit

Permalink
Fix parser with # (#147)
Browse files Browse the repository at this point in the history
Co-authored-by: xxchan <xxchan22f@gmail.com>
  • Loading branch information
xudong963 and xxchan committed Jan 15, 2023
1 parent f4e2121 commit 681f65b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion sqllogictest-bin/src/engines/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl AsyncDB for ExternalDriver {
};
match output {
Output::Success { result } => Ok(DBOutput::Rows {
types: vec![], // FIXME: Fix it after https://github.com/risinglightdb/sqllogictest-rs/issues/36 is resolved.
types: vec![], /* FIXME: Fix it after https://github.com/risinglightdb/sqllogictest-rs/issues/36 is resolved. */
rows: result,
}),
Output::Failed { err } => Err(ExternalDriverError::Sql(err)),
Expand Down
38 changes: 27 additions & 11 deletions sqllogictest/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,24 +397,24 @@ pub fn parse(script: &str) -> Result<Vec<Record>, ParseError> {

#[allow(clippy::collapsible_match)]
fn parse_inner(loc: &Location, script: &str) -> Result<Vec<Record>, ParseError> {
let mut lines = script.lines().enumerate();
let mut lines = script.lines().enumerate().peekable();
let mut records = vec![];
let mut conditions = vec![];
let mut comments = vec![];

while let Some((mut num, mut line)) = lines.next() {
while let Some((num, line)) = lines.next() {
if let Some(text) = line.strip_prefix('#') {
let mut comments = vec![text.to_string()];
for (num_, line_) in lines.by_ref() {
num = num_;
line = line_;
if let Some(text) = line.strip_prefix('#') {
comments.push(text.to_string());
} else {
break;
}
comments.push(text.to_string());
if lines.peek().is_none() {
records.push(Record::Comment(comments));
comments = vec![];
}
continue;
}

if !comments.is_empty() {
records.push(Record::Comment(comments));
comments = vec![];
}

if line.is_empty() {
Expand Down Expand Up @@ -635,6 +635,22 @@ mod tests {

use super::*;

#[test]
fn test_trailing_comment() {
let script = "\
# comment 1
# comment 2
";
let records = parse(script).unwrap();
assert_eq!(
records,
vec![Record::Comment(vec![
" comment 1".to_string(),
" comment 2".to_string(),
]),]
);
}

#[test]
fn test_include_glob() {
let records = parse_file("../examples/include/include_1.slt").unwrap();
Expand Down

0 comments on commit 681f65b

Please sign in to comment.