logic base

This commit is contained in:
Folkert 2022-05-15 00:00:32 +02:00
parent dc4f8289ad
commit 8f97c217a5
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C

View file

@ -277,10 +277,15 @@ fn eat_line_comment<'a>(
) -> SpaceState<'a> {
use SpaceState::*;
let is_doc_comment = if let Some(b'#') = state.bytes().get(0) {
match state.bytes().get(1) {
let mut index = 0;
let bytes = state.bytes();
'outer: loop {
let is_doc_comment = if let Some(b'#') = bytes.get(index) {
match bytes.get(index + 1) {
Some(b' ') => {
state = state.advance(2);
index += 2;
true
}
@ -288,6 +293,7 @@ fn eat_line_comment<'a>(
// consume the second # and the \n
state = state.advance(1);
state = state.advance_newline();
index += 2;
comments_and_newlines.push(CommentOrNewline::DocComment(""));
multiline = true;
@ -299,6 +305,7 @@ fn eat_line_comment<'a>(
}
b'\n' => {
state = state.advance_newline();
index += 1;
multiline = true;
comments_and_newlines.push(CommentOrNewline::Newline);
}
@ -310,10 +317,13 @@ fn eat_line_comment<'a>(
}
b'#' => {
state = state.advance(1);
return eat_line_comment(state, multiline, comments_and_newlines);
index += 1;
continue 'outer;
}
_ => break,
}
index += 1;
}
return Good {
@ -339,6 +349,8 @@ fn eat_line_comment<'a>(
false
};
let loop_start = index;
let initial = state.bytes();
let mut it = initial.iter();
@ -357,6 +369,7 @@ fn eat_line_comment<'a>(
state = state.advance_newline();
multiline = true;
index += 1;
while let Some(c) = it.next() {
match c {
b' ' => {
@ -375,10 +388,13 @@ fn eat_line_comment<'a>(
}
b'#' => {
state = state.advance(1);
return eat_line_comment(state, multiline, comments_and_newlines);
index += 1;
continue 'outer;
}
_ => break,
}
index += 1;
}
return Good {
@ -394,11 +410,13 @@ fn eat_line_comment<'a>(
state = state.advance(1);
}
}
index += 1;
}
// We made it to the end of the bytes. This means there's a comment without a trailing newline.
let delta = initial.len() - state.bytes().len();
let comment = unsafe { std::str::from_utf8_unchecked(&initial[..delta]) };
let comment = unsafe { std::str::from_utf8_unchecked(&bytes[loop_start..delta]) };
if is_doc_comment {
comments_and_newlines.push(CommentOrNewline::DocComment(comment));
@ -406,9 +424,10 @@ fn eat_line_comment<'a>(
comments_and_newlines.push(CommentOrNewline::LineComment(comment));
}
Good {
return Good {
state,
multiline,
comments_and_newlines,
};
}
}