parameterize Parser on an Error type

This commit is contained in:
Folkert 2021-02-07 22:08:28 +01:00
parent da28486184
commit 148fffe969
17 changed files with 372 additions and 271 deletions

View file

@ -1,10 +1,12 @@
use crate::ast::{Attempting, Base, Expr};
use crate::parser::{parse_utf8, unexpected, unexpected_eof, ParseResult, Parser, Progress, State};
use crate::parser::{
parse_utf8, unexpected, unexpected_eof, ParseResult, Parser, Progress, State, SyntaxError,
};
use bumpalo::Bump;
use std::char;
use std::str::from_utf8_unchecked;
pub fn number_literal<'a>() -> impl Parser<'a, Expr<'a>> {
pub fn number_literal<'a>() -> impl Parser<'a, Expr<'a>, SyntaxError> {
move |arena, state: State<'a>| {
let bytes = &mut state.bytes.iter();
@ -28,7 +30,7 @@ fn parse_number_literal<'a, I>(
bytes: &mut I,
arena: &'a Bump,
state: State<'a>,
) -> ParseResult<'a, Expr<'a>>
) -> ParseResult<'a, Expr<'a>, SyntaxError>
where
I: Iterator<Item = &'a u8>,
{
@ -164,7 +166,7 @@ fn from_base<'a>(
bytes_parsed: usize,
arena: &'a Bump,
state: State<'a>,
) -> ParseResult<'a, Expr<'a>> {
) -> ParseResult<'a, Expr<'a>, SyntaxError> {
let is_negative = first_ch == '-';
let bytes = if is_negative {
&state.bytes[3..bytes_parsed]