mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 22:09:09 +00:00

* Remove the `pos` field, which was always being assigned Position::default() * Remove one use of this `pos`, by removing the never-used SyntaxError::ConditionFailed variant * Adjust the other use to do what was probably intended - which is to say, pointing to the beginning of the def with the error * Rename to FileError, reuse `SourceError` as an inner field, to avoid duplicating the `bytes`
45 lines
1.2 KiB
Rust
45 lines
1.2 KiB
Rust
use crate::ast;
|
|
use crate::module::module_defs;
|
|
// use crate::module::module_defs;
|
|
use crate::parser::Parser;
|
|
use crate::parser::SourceError;
|
|
use crate::parser::SyntaxError;
|
|
use crate::state::State;
|
|
use bumpalo::collections::Vec as BumpVec;
|
|
use bumpalo::Bump;
|
|
use roc_region::all::Loc;
|
|
use roc_region::all::Position;
|
|
|
|
pub fn parse_expr_with<'a>(
|
|
arena: &'a Bump,
|
|
input: &'a str,
|
|
) -> Result<ast::Expr<'a>, SyntaxError<'a>> {
|
|
parse_loc_with(arena, input)
|
|
.map(|loc_expr| loc_expr.value)
|
|
.map_err(|e| e.problem)
|
|
}
|
|
|
|
#[allow(dead_code)]
|
|
pub fn parse_loc_with<'a>(
|
|
arena: &'a Bump,
|
|
input: &'a str,
|
|
) -> Result<Loc<ast::Expr<'a>>, SourceError<'a, SyntaxError<'a>>> {
|
|
let state = State::new(input.trim().as_bytes());
|
|
|
|
match crate::expr::test_parse_expr(0, arena, state.clone()) {
|
|
Ok(loc_expr) => Ok(loc_expr),
|
|
Err(fail) => Err(SyntaxError::Expr(fail, Position::default()).into_source_error(&state)),
|
|
}
|
|
}
|
|
|
|
pub fn parse_defs_with<'a>(
|
|
arena: &'a Bump,
|
|
input: &'a str,
|
|
) -> Result<BumpVec<'a, Loc<ast::Def<'a>>>, SyntaxError<'a>> {
|
|
let state = State::new(input.trim().as_bytes());
|
|
|
|
match module_defs().parse(arena, state) {
|
|
Ok(tuple) => Ok(tuple.1),
|
|
Err(tuple) => Err(tuple.1),
|
|
}
|
|
}
|