mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 00:01:16 +00:00
parameterize Parser on an Error type
This commit is contained in:
parent
da28486184
commit
148fffe969
17 changed files with 372 additions and 271 deletions
|
@ -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]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue