remove arena argument

This commit is contained in:
Folkert 2021-02-26 15:09:52 +01:00
parent bb9a2525b5
commit fed292811f
6 changed files with 14 additions and 25 deletions

View file

@ -358,7 +358,7 @@ pub fn line_comment<'a>() -> impl Parser<'a, &'a str, SyntaxError<'a>> {
and!(ascii_char(b'#'), optional(ascii_string("# "))), and!(ascii_char(b'#'), optional(ascii_string("# "))),
|arena: &'a Bump, state: State<'a>, _, (_, opt_doc)| { |arena: &'a Bump, state: State<'a>, _, (_, opt_doc)| {
if opt_doc != None { if opt_doc != None {
return Err(unexpected(arena, 3, Attempting::LineComment, state)); return Err(unexpected(3, Attempting::LineComment, state));
} }
let mut length = 0; let mut length = 0;
@ -401,7 +401,6 @@ pub fn spaces_exactly<'a>(spaces_expected: u16) -> impl Parser<'a, (), SyntaxErr
} }
Ok(_) => { Ok(_) => {
return Err(unexpected( return Err(unexpected(
arena,
spaces_seen.into(), spaces_seen.into(),
Attempting::TODO, Attempting::TODO,
state.clone(), state.clone(),
@ -418,7 +417,6 @@ pub fn spaces_exactly<'a>(spaces_expected: u16) -> impl Parser<'a, (), SyntaxErr
return Err(unexpected_eof(arena, state, 0)); return Err(unexpected_eof(arena, state, 0));
} else { } else {
return Err(unexpected( return Err(unexpected(
arena,
spaces_seen.into(), spaces_seen.into(),
Attempting::TODO, Attempting::TODO,
state.clone(), state.clone(),
@ -431,12 +429,7 @@ pub fn spaces_exactly<'a>(spaces_expected: u16) -> impl Parser<'a, (), SyntaxErr
if spaces_seen == 0 { if spaces_seen == 0 {
Err(unexpected_eof(arena, state, 0)) Err(unexpected_eof(arena, state, 0))
} else { } else {
Err(unexpected( Err(unexpected(spaces_seen.into(), Attempting::TODO, state))
arena,
spaces_seen.into(),
Attempting::TODO,
state,
))
} }
} }
} }

View file

@ -1851,7 +1851,7 @@ pub fn equals_with_indent<'a>() -> impl Parser<'a, u16, SyntaxError<'a>> {
match state.bytes.get(1) { match state.bytes.get(1) {
// The '=' must not be followed by another `=` or `>` // The '=' must not be followed by another `=` or `>`
// (See equals_for_def() for explanation) // (See equals_for_def() for explanation)
Some(b'=') | Some(b'>') => Err(unexpected(arena, 0, Attempting::Def, state)), Some(b'=') | Some(b'>') => Err(unexpected(0, Attempting::Def, state)),
Some(_) => Ok(( Some(_) => Ok((
MadeProgress, MadeProgress,
state.indent_col, state.indent_col,
@ -1864,7 +1864,7 @@ pub fn equals_with_indent<'a>() -> impl Parser<'a, u16, SyntaxError<'a>> {
)), )),
} }
} }
Some(_) => Err(unexpected(arena, 0, Attempting::Def, state)), Some(_) => Err(unexpected(0, Attempting::Def, state)),
None => Err(unexpected_eof(arena, state, 0)), None => Err(unexpected_eof(arena, state, 0)),
} }
} }
@ -1877,7 +1877,7 @@ pub fn colon_with_indent<'a>() -> impl Parser<'a, u16, SyntaxError<'a>> {
state.indent_col, state.indent_col,
state.advance_without_indenting(1)?, state.advance_without_indenting(1)?,
)), )),
Some(_) => Err(unexpected(arena, 0, Attempting::Def, state)), Some(_) => Err(unexpected(0, Attempting::Def, state)),
None => Err(unexpected_eof(arena, state, 0)), None => Err(unexpected_eof(arena, state, 0)),
} }
} }

View file

@ -114,7 +114,6 @@ pub fn parse_ident<'a>(
is_accessor_fn = false; is_accessor_fn = false;
} else { } else {
return Err(unexpected( return Err(unexpected(
arena,
bytes_parsed + next_bytes_parsed, bytes_parsed + next_bytes_parsed,
Attempting::Identifier, Attempting::Identifier,
state, state,
@ -127,7 +126,7 @@ pub fn parse_ident<'a>(
} }
} }
} else { } else {
return Err(unexpected(arena, 0, Attempting::Identifier, state)); return Err(unexpected(0, Attempting::Identifier, state));
} }
} }
Err(reason) => { Err(reason) => {
@ -254,7 +253,7 @@ pub fn parse_ident<'a>(
// We had neither capitalized nor noncapitalized parts, // We had neither capitalized nor noncapitalized parts,
// yet we made it this far. The only explanation is that this was // yet we made it this far. The only explanation is that this was
// a stray '.' drifting through the cosmos. // a stray '.' drifting through the cosmos.
return Err(unexpected(arena, 1, Attempting::Identifier, state)); return Err(unexpected(1, Attempting::Identifier, state));
} }
} }
} else if is_private_tag { } else if is_private_tag {
@ -339,7 +338,7 @@ where
let (first_letter, bytes_parsed) = match peek_utf8_char(&state) { let (first_letter, bytes_parsed) = match peek_utf8_char(&state) {
Ok((first_letter, bytes_parsed)) => { Ok((first_letter, bytes_parsed)) => {
if !pred(first_letter) { if !pred(first_letter) {
return Err(unexpected(arena, 0, Attempting::RecordFieldLabel, state)); return Err(unexpected(0, Attempting::RecordFieldLabel, state));
} }
(first_letter, bytes_parsed) (first_letter, bytes_parsed)

View file

@ -121,7 +121,7 @@ pub fn module_name<'a>() -> impl Parser<'a, ModuleName<'a>, SyntaxError<'a>> {
match peek_utf8_char(&state) { match peek_utf8_char(&state) {
Ok((first_letter, bytes_parsed)) => { Ok((first_letter, bytes_parsed)) => {
if !first_letter.is_uppercase() { if !first_letter.is_uppercase() {
return Err(unexpected(arena, 0, Attempting::Module, state)); return Err(unexpected(0, Attempting::Module, state));
}; };
let mut buf = String::with_capacity_in(4, arena); let mut buf = String::with_capacity_in(4, arena);

View file

@ -880,7 +880,6 @@ pub fn unexpected_eof<'a>(
} }
pub fn unexpected<'a>( pub fn unexpected<'a>(
arena: &'a Bump,
chars_consumed: usize, chars_consumed: usize,
_attempting: Attempting, _attempting: Attempting,
state: State<'a>, state: State<'a>,
@ -968,7 +967,7 @@ pub fn ascii_char<'a>(expected: u8) -> impl Parser<'a, (), SyntaxError<'a>> {
(), (),
state.advance_without_indenting(1)?, state.advance_without_indenting(1)?,
)), )),
Some(_) => Err(unexpected(arena, 0, Attempting::Keyword, state)), Some(_) => Err(unexpected(0, Attempting::Keyword, state)),
_ => Err(unexpected_eof(arena, state, 0)), _ => Err(unexpected_eof(arena, state, 0)),
} }
} }
@ -979,7 +978,7 @@ pub fn ascii_char<'a>(expected: u8) -> impl Parser<'a, (), SyntaxError<'a>> {
pub fn newline_char<'a>() -> impl Parser<'a, (), SyntaxError<'a>> { pub fn newline_char<'a>() -> impl Parser<'a, (), SyntaxError<'a>> {
move |arena, state: State<'a>| match state.bytes.first() { move |arena, state: State<'a>| match state.bytes.first() {
Some(b'\n') => Ok((Progress::MadeProgress, (), state.newline(arena)?)), Some(b'\n') => Ok((Progress::MadeProgress, (), state.newline(arena)?)),
Some(_) => Err(unexpected(arena, 0, Attempting::Keyword, state)), Some(_) => Err(unexpected(0, Attempting::Keyword, state)),
_ => Err(unexpected_eof(arena, state, 0)), _ => Err(unexpected_eof(arena, state, 0)),
} }
} }
@ -995,7 +994,7 @@ pub fn ascii_hex_digits<'a>() -> impl Parser<'a, &'a str, SyntaxError<'a>> {
buf.push(byte as char); buf.push(byte as char);
} else if buf.is_empty() { } else if buf.is_empty() {
// We didn't find any hex digits! // We didn't find any hex digits!
return Err(unexpected(arena, 0, Attempting::Keyword, state)); return Err(unexpected(0, Attempting::Keyword, state));
} else { } else {
let state = state.advance_without_indenting(buf.len())?; let state = state.advance_without_indenting(buf.len())?;
@ -1144,7 +1143,7 @@ pub fn ascii_string<'a>(keyword: &'static str) -> impl Parser<'a, (), SyntaxErro
state.advance_without_indenting(len)?, state.advance_without_indenting(len)?,
)) ))
} else { } else {
let (_, fail, state) = unexpected(arena, len, Attempting::Keyword, state); let (_, fail, state) = unexpected(len, Attempting::Keyword, state);
Err((NoProgress, fail, state)) Err((NoProgress, fail, state))
} }
} }

View file

@ -18,7 +18,7 @@ pub fn parse<'a>() -> impl Parser<'a, StrLiteral<'a>, SyntaxError<'a>> {
match bytes.next() { match bytes.next() {
Some(&byte) => { Some(&byte) => {
if byte != b'"' { if byte != b'"' {
return Err(unexpected(arena, 0, Attempting::StrLiteral, state)); return Err(unexpected(0, Attempting::StrLiteral, state));
} }
} }
None => { None => {
@ -138,7 +138,6 @@ pub fn parse<'a>() -> impl Parser<'a, StrLiteral<'a>, SyntaxError<'a>> {
// it should make it easiest to debug; the file will be a giant // it should make it easiest to debug; the file will be a giant
// error starting from where the open quote appeared. // error starting from where the open quote appeared.
return Err(unexpected( return Err(unexpected(
arena,
state.bytes.len() - 1, state.bytes.len() - 1,
Attempting::StrLiteral, Attempting::StrLiteral,
state, state,
@ -229,7 +228,6 @@ pub fn parse<'a>() -> impl Parser<'a, StrLiteral<'a>, SyntaxError<'a>> {
// by either an open paren or else one of the // by either an open paren or else one of the
// escapable characters (\n, \t, \", \\, etc) // escapable characters (\n, \t, \", \\, etc)
return Err(unexpected( return Err(unexpected(
arena,
state.bytes.len() - 1, state.bytes.len() - 1,
Attempting::StrLiteral, Attempting::StrLiteral,
state, state,