Add doc comment new line parsing

This commit is contained in:
Pablo Hirafuji 2020-11-06 13:57:41 -03:00
parent 00130c6dc0
commit 0c20713f94
2 changed files with 27 additions and 8 deletions

View file

@ -317,11 +317,26 @@ fn spaces<'a>(
'\n' => { '\n' => {
state = state.newline()?; state = state.newline()?;
// This was a newline, so end this line comment. match (comment_line_buf.len(), comment_line_buf.chars().next())
space_list.push(LineComment(comment_line_buf.into_bump_str())); {
comment_line_buf = String::new_in(arena); (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 => { nonblank => {
// Chars can have btye lengths of more than 1! // Chars can have btye lengths of more than 1!

View file

@ -2345,18 +2345,20 @@ mod test_parse {
let arena = Bump::new(); let arena = Bump::new();
let newlines = &[Newline, Newline]; let newlines = &[Newline, Newline];
let def = Def::Body( let def = Def::Body(
arena.alloc(Located::new(4, 4, 0, 1, Identifier("x"))), arena.alloc(Located::new(6, 6, 0, 1, Identifier("x"))),
arena.alloc(Located::new(4, 4, 4, 5, Num("5"))), 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 defs = &[loc_def];
let ret = Expr::SpaceBefore(arena.alloc(Num("42")), newlines); 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 = &[ let reset_indentation = &[
DocComment("first line of docs"), DocComment("first line of docs"),
DocComment(" second line"), DocComment(" second line"),
DocComment(" third line"), DocComment(" third line"),
DocComment("fourth line"), DocComment("fourth line"),
DocComment(""),
DocComment("sixth line after doc new line"),
]; ];
let expected = Expr::SpaceBefore( let expected = Expr::SpaceBefore(
arena.alloc(Defs(defs, arena.alloc(loc_ret))), arena.alloc(Defs(defs, arena.alloc(loc_ret))),
@ -2370,6 +2372,8 @@ mod test_parse {
## second line ## second line
## third line ## third line
## fourth line ## fourth line
##
## sixth line after doc new line
x = 5 x = 5
42 42