Preserve newlines after blocks of comments.
This is an example of output from the formatter now:
```
//// Some module documentation
// foo
const a: Int = 42
// Some comment block
// For which newlines are respected.
// Foo
// Another one
/// add_one documentation
pub fn add_one(n: Int) -> Int {
// n + 1
n + 1
}
```
before this commit, comments would all be collapsed into one group
above the function as:
```
// Some comment block
// For which newlines are respected.
// Foo
// Another one
/// add_one documentation
pub fn add_one(n: Int) -> Int {
```
This commit is contained in:
parent
22a526bb13
commit
431b0cfcf2
|
|
@ -47,7 +47,6 @@ pub fn module(
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
Token::EmptyLine => {
|
Token::EmptyLine => {
|
||||||
println!("{:?}", span);
|
|
||||||
extra.empty_lines.push(span.start);
|
extra.empty_lines.push(span.start);
|
||||||
|
|
||||||
false
|
false
|
||||||
|
|
|
||||||
|
|
@ -117,10 +117,17 @@ pub fn lexer() -> impl Parser<char, Vec<(Token, Span)>, Error = ParseError> {
|
||||||
.map_with_span(|token, span| (token, span)),
|
.map_with_span(|token, span| (token, span)),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let comments_with_trailing_newline = just("//").ignore_then(
|
||||||
|
take_until(text::newline())
|
||||||
|
.then_ignore(text::newline().rewind())
|
||||||
|
.to(Token::Comment)
|
||||||
|
.map_with_span(|token, span| (token, span)),
|
||||||
|
);
|
||||||
|
|
||||||
choice((
|
choice((
|
||||||
module_comments,
|
module_comments,
|
||||||
doc_comments,
|
doc_comments,
|
||||||
comments,
|
choice((comments_with_trailing_newline, comments)),
|
||||||
choice((keyword, int, op, grouping, string))
|
choice((keyword, int, op, grouping, string))
|
||||||
.or(any().map(Token::Error).validate(|t, span, emit| {
|
.or(any().map(Token::Error).validate(|t, span, emit| {
|
||||||
emit(ParseError::expected_input_found(
|
emit(ParseError::expected_input_found(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue