mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-22 04:44:06 +00:00
Refactor: introduce trait SpaceProblem to remove a bunch of redundant args in ::Space errors
This commit is contained in:
parent
999287e958
commit
f440d53e7b
7 changed files with 117 additions and 170 deletions
|
@ -63,6 +63,50 @@ pub enum SyntaxError<'a> {
|
|||
Space(BadInputError),
|
||||
NotEndOfFile(Position),
|
||||
}
|
||||
pub trait SpaceProblem {
|
||||
fn space_problem(e: BadInputError, pos: Position) -> Self;
|
||||
}
|
||||
|
||||
macro_rules! impl_space_problem {
|
||||
($($name:ident $(< $lt:tt >)?),*) => {
|
||||
$(
|
||||
impl $(< $lt >)? SpaceProblem for $name $(< $lt >)? {
|
||||
fn space_problem(e: BadInputError, pos: Position) -> Self {
|
||||
Self::Space(e, pos)
|
||||
}
|
||||
}
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
||||
impl_space_problem! {
|
||||
EExpect<'a>,
|
||||
EExposes,
|
||||
EExpr<'a>,
|
||||
EGenerates,
|
||||
EGeneratesWith,
|
||||
EHeader<'a>,
|
||||
EIf<'a>,
|
||||
EImports,
|
||||
EInParens<'a>,
|
||||
ELambda<'a>,
|
||||
EList<'a>,
|
||||
EPackageEntry<'a>,
|
||||
EPackages<'a>,
|
||||
EPattern<'a>,
|
||||
EProvides<'a>,
|
||||
ERecord<'a>,
|
||||
ERequires<'a>,
|
||||
EString<'a>,
|
||||
EType<'a>,
|
||||
ETypeInParens<'a>,
|
||||
ETypeRecord<'a>,
|
||||
ETypeTagUnion<'a>,
|
||||
ETypedIdent<'a>,
|
||||
EWhen<'a>,
|
||||
PInParens<'a>,
|
||||
PRecord<'a>
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum EHeader<'a> {
|
||||
|
@ -505,6 +549,8 @@ pub enum PInParens<'a> {
|
|||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum EType<'a> {
|
||||
Space(BadInputError, Position),
|
||||
|
||||
TRecord(ETypeRecord<'a>, Position),
|
||||
TTagUnion(ETypeTagUnion<'a>, Position),
|
||||
TInParens(ETypeInParens<'a>, Position),
|
||||
|
@ -516,7 +562,6 @@ pub enum EType<'a> {
|
|||
///
|
||||
TStart(Position),
|
||||
TEnd(Position),
|
||||
TSpace(BadInputError, Position),
|
||||
TFunctionArgument(Position),
|
||||
///
|
||||
TIndentStart(Position),
|
||||
|
@ -1153,11 +1198,11 @@ macro_rules! collection {
|
|||
|
||||
#[macro_export]
|
||||
macro_rules! collection_trailing_sep_e {
|
||||
($opening_brace:expr, $elem:expr, $delimiter:expr, $closing_brace:expr, $min_indent:expr, $open_problem:expr, $space_problem:expr, $indent_problem:expr, $space_before:expr) => {
|
||||
($opening_brace:expr, $elem:expr, $delimiter:expr, $closing_brace:expr, $min_indent:expr, $open_problem:expr, $indent_problem:expr, $space_before:expr) => {
|
||||
skip_first!(
|
||||
$opening_brace,
|
||||
|arena, state| {
|
||||
let (_, spaces, state) = space0_e($min_indent, $space_problem, $indent_problem)
|
||||
let (_, spaces, state) = space0_e($min_indent, $indent_problem)
|
||||
.parse(arena, state)?;
|
||||
|
||||
let (_, (mut parsed_elems, mut final_comments), state) =
|
||||
|
@ -1167,12 +1212,11 @@ macro_rules! collection_trailing_sep_e {
|
|||
$crate::blankspace::space0_before_optional_after(
|
||||
$elem,
|
||||
$min_indent,
|
||||
$space_problem,
|
||||
$indent_problem,
|
||||
$indent_problem
|
||||
)
|
||||
),
|
||||
$crate::blankspace::space0_e($min_indent, $space_problem, $indent_problem)
|
||||
$crate::blankspace::space0_e($min_indent, $indent_problem)
|
||||
).parse(arena, state)?;
|
||||
|
||||
let (_,_, state) =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue