removing old stuff

This commit is contained in:
Folkert 2021-03-12 01:37:27 +01:00
parent f5d3845b14
commit 4f58c792e6
5 changed files with 85 additions and 385 deletions

View file

@ -249,6 +249,50 @@ fn chomp_line_comment<'a>(buffer: &'a [u8]) -> Result<&'a str, Progress> {
}
}
/// Advance the parser while also indenting as appropriate.
/// This assumes we are only advancing with spaces, since they can indent.
fn advance_spaces_e<'a, TE, E>(
state: &State<'a>,
spaces: usize,
to_error: TE,
) -> Result<State<'a>, (Progress, E, State<'a>)>
where
TE: Fn(Row, Col) -> E,
{
match (state.column as usize).checked_add(spaces) {
Some(column_usize) if column_usize <= u16::MAX as usize => {
// Spaces don't affect is_indenting; if we were previously indneting,
// we still are, and if we already finished indenting, we're still done.
let is_indenting = state.is_indenting;
// If we're indenting, spaces indent us further.
let indent_col = if is_indenting {
// This doesn't need to be checked_add because it's always true that
// indent_col <= col, so if this could possibly overflow, we would
// already have errored out from the column calculation.
//
// Leaving debug assertions in case this invariant someday disappers.
debug_assert!(u16::MAX - state.indent_col >= spaces as u16);
debug_assert!(spaces <= u16::MAX as usize);
state.indent_col + spaces as u16
} else {
state.indent_col
};
Ok(State {
bytes: &state.bytes[spaces..],
line: state.line,
column: column_usize as u16,
indent_col,
is_indenting,
original_len: state.original_len,
})
}
_ => Err(crate::parser::line_too_long_e(state.clone(), to_error)),
}
}
#[inline(always)]
pub fn spaces_exactly_e<'a>(spaces_expected: u16) -> impl Parser<'a, (), parser::EExpr<'a>> {
use parser::EExpr;
@ -266,7 +310,7 @@ pub fn spaces_exactly_e<'a>(spaces_expected: u16) -> impl Parser<'a, (), parser:
spaces_seen += 1;
if spaces_seen == spaces_expected {
let state =
state.advance_spaces_e(spaces_expected as usize, EExpr::IndentStart)?;
advance_spaces_e(&state, spaces_expected as usize, EExpr::IndentStart)?;
return Ok((MadeProgress, (), state));
}
}