diff --git a/crates/nu-parser/src/lex.rs b/crates/nu-parser/src/lex.rs index 40f2baaac4..34701efdf4 100644 --- a/crates/nu-parser/src/lex.rs +++ b/crates/nu-parser/src/lex.rs @@ -388,7 +388,24 @@ fn lex_internal( *prev = Token::new( TokenContents::Pipe, Span::new(span_offset + idx, span_offset + idx + 1), - ) + ); + // And this is a continuation of the previous line if previous line is a + // comment line (combined with EOL + Comment) + // + // Initially, the last one token is TokenContents::Pipe, we don't need to + // check it, so the beginning offset is 2. + let mut offset = 2; + while output.len() > offset { + let index = output.len() - offset; + if output[index].contents == TokenContents::Comment + && output[index - 1].contents == TokenContents::Eol + { + output.remove(index - 1); + offset += 1; + } else { + break; + } + } } _ => { output.push(Token::new( diff --git a/src/tests/test_parser.rs b/src/tests/test_parser.rs index 510c4220f0..3382aa9c7a 100644 --- a/src/tests/test_parser.rs +++ b/src/tests/test_parser.rs @@ -442,6 +442,16 @@ fn unary_not_6() -> TestResult { ) } +#[test] +fn comment_in_multiple_pipelines() -> TestResult { + run_test( + r#"[[name, present]; [abc, true], [def, false]] + # | where not present + | get name.0"#, + "abc", + ) +} + #[test] fn date_literal() -> TestResult { run_test(r#"2022-09-10 | date to-record | get day"#, "10")