mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 06:44:46 +00:00
Introduce SourceError to represent an error + original source
This commit is contained in:
parent
8d6eb178b1
commit
5c1084c453
9 changed files with 96 additions and 48 deletions
|
@ -8,7 +8,7 @@ use crate::ident::{lowercase_ident, unqualified_ident, uppercase_ident};
|
|||
use crate::parser::Progress::{self, *};
|
||||
use crate::parser::{
|
||||
backtrackable, specialize, word1, word2, EEffects, EExposes, EHeader, EImports, EPackages,
|
||||
EProvides, ERequires, ETypedIdent, Parser, SyntaxError,
|
||||
EProvides, ERequires, ETypedIdent, Parser, SyntaxError, SourceError,
|
||||
};
|
||||
use crate::state::State;
|
||||
use crate::string_literal;
|
||||
|
@ -39,10 +39,10 @@ pub fn module_defs<'a>() -> impl Parser<'a, Vec<'a, Loc<Def<'a>>>, SyntaxError<'
|
|||
pub fn parse_header<'a>(
|
||||
arena: &'a bumpalo::Bump,
|
||||
state: State<'a>,
|
||||
) -> Result<(Module<'a>, State<'a>), EHeader<'a>> {
|
||||
) -> Result<(Module<'a>, State<'a>), SourceError<'a, EHeader<'a>>> {
|
||||
match header().parse(arena, state) {
|
||||
Ok((_, module, state)) => Ok((module, state)),
|
||||
Err((_, fail, _)) => Err(fail),
|
||||
Err((_, fail, state)) => Err(SourceError::new(fail, &state)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -167,6 +167,7 @@ fn module_name<'a>() -> impl Parser<'a, ModuleName<'a>, ()> {
|
|||
|_, mut state: State<'a>| match chomp_module_name(state.bytes()) {
|
||||
Ok(name) => {
|
||||
let width = name.len();
|
||||
state.xyzlcol.column += width as u16;
|
||||
state = state.advance(width);
|
||||
|
||||
Ok((MadeProgress, ModuleName::new(name), state))
|
||||
|
@ -435,7 +436,7 @@ fn platform_requires<'a>() -> impl Parser<'a, PlatformRequires<'a>, ERequires<'a
|
|||
|
||||
#[inline(always)]
|
||||
fn requires_rigids<'a>(
|
||||
min_indent: u32,
|
||||
min_indent: u16,
|
||||
) -> impl Parser<'a, Collection<'a, Loc<Spaced<'a, PlatformRigid<'a>>>>, ERequires<'a>> {
|
||||
collection_trailing_sep_e!(
|
||||
word1(b'{', ERequires::ListStart),
|
||||
|
@ -513,7 +514,7 @@ fn exposes_values<'a>() -> impl Parser<
|
|||
}
|
||||
|
||||
fn spaces_around_keyword<'a, E>(
|
||||
min_indent: u32,
|
||||
min_indent: u16,
|
||||
keyword: &'static str,
|
||||
expectation: fn(Position) -> E,
|
||||
space_problem: fn(crate::parser::BadInputError, Position) -> E,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue