diff --git a/compiler/parse/src/blankspace.rs b/compiler/parse/src/blankspace.rs index 8a9e5fb388..02f290f0ad 100644 --- a/compiler/parse/src/blankspace.rs +++ b/compiler/parse/src/blankspace.rs @@ -317,11 +317,26 @@ fn spaces<'a>( '\n' => { state = state.newline()?; - // This was a newline, so end this line comment. - space_list.push(LineComment(comment_line_buf.into_bump_str())); - comment_line_buf = String::new_in(arena); + match (comment_line_buf.len(), comment_line_buf.chars().next()) + { + (1, Some('#')) => { + // This is a line with `##` - that is, + // a doc comment new line. + space_list.push(DocComment("")); + comment_line_buf = String::new_in(arena); - line_state = LineState::Normal; + line_state = LineState::Normal; + } + _ => { + // This was a newline, so end this line comment. + space_list.push(LineComment( + comment_line_buf.into_bump_str(), + )); + comment_line_buf = String::new_in(arena); + + line_state = LineState::Normal; + } + } } nonblank => { // Chars can have btye lengths of more than 1! diff --git a/compiler/parse/tests/test_parse.rs b/compiler/parse/tests/test_parse.rs index 8c94db8d72..d00da909e2 100644 --- a/compiler/parse/tests/test_parse.rs +++ b/compiler/parse/tests/test_parse.rs @@ -2345,18 +2345,20 @@ mod test_parse { let arena = Bump::new(); let newlines = &[Newline, Newline]; let def = Def::Body( - arena.alloc(Located::new(4, 4, 0, 1, Identifier("x"))), - arena.alloc(Located::new(4, 4, 4, 5, Num("5"))), + arena.alloc(Located::new(6, 6, 0, 1, Identifier("x"))), + arena.alloc(Located::new(6, 6, 4, 5, Num("5"))), ); - let loc_def = &*arena.alloc(Located::new(4, 4, 0, 1, def)); + let loc_def = &*arena.alloc(Located::new(6, 6, 0, 1, def)); let defs = &[loc_def]; let ret = Expr::SpaceBefore(arena.alloc(Num("42")), newlines); - let loc_ret = Located::new(6, 6, 0, 2, ret); + let loc_ret = Located::new(8, 8, 0, 2, ret); let reset_indentation = &[ DocComment("first line of docs"), DocComment(" second line"), DocComment(" third line"), DocComment("fourth line"), + DocComment(""), + DocComment("sixth line after doc new line"), ]; let expected = Expr::SpaceBefore( arena.alloc(Defs(defs, arena.alloc(loc_ret))), @@ -2370,6 +2372,8 @@ mod test_parse { ## second line ## third line ## fourth line + ## + ## sixth line after doc new line x = 5 42