Centralize the macro fallbacks

This commit is contained in:
Richard Feldman 2019-11-20 06:26:11 -05:00
parent e850703ca9
commit cbbe80eeca
3 changed files with 26 additions and 40 deletions

View file

@ -3,23 +3,9 @@ use bumpalo::collections::vec::Vec;
use bumpalo::Bump;
use parse::ast::CommentOrNewline::{self, *};
use parse::ast::Spaceable;
use parse::parser::{map_with_arena, unexpected, unexpected_eof, Parser, State};
use parse::parser::{and, map_with_arena, unexpected, unexpected_eof, Parser, State};
use region::Located;
/// For some reason, some functions need to use this instead of using the and! macro directly.
#[inline(always)]
pub fn and<'a, P1, P2, A, B>(p1: P1, p2: P2) -> impl Parser<'a, (A, B)>
where
P1: Parser<'a, A>,
P2: Parser<'a, B>,
P1: 'a,
P2: 'a,
A: 'a,
B: 'a,
{
and!(p1, p2)
}
/// Parses the given expression with 0 or more (spaces/comments/newlines) before and/or after it.
/// Returns a Located<Expr> where the location is around the Expr, ignoring the spaces.
/// If any newlines or comments were found, the Expr will be wrapped in a SpaceBefore and/or

View file

@ -1,7 +1,7 @@
use bumpalo::collections::vec::Vec;
use bumpalo::Bump;
use parse::ast::Attempting;
use region::Region;
use region::{Located, Region};
use std::{char, u16};
/// A position in a source file.
@ -1359,3 +1359,26 @@ macro_rules! and {
}
};
}
/// For some reason, some usages won't compile unless they use this instead of the macro version
#[inline(always)]
pub fn and<'a, P1, P2, A, B>(p1: P1, p2: P2) -> impl Parser<'a, (A, B)>
where
P1: Parser<'a, A>,
P2: Parser<'a, B>,
P1: 'a,
P2: 'a,
A: 'a,
B: 'a,
{
and!(p1, p2)
}
/// For some reason, some usages won't compile unless they use this instead of the macro version
#[inline(always)]
pub fn loc<'a, P, Val>(parser: P) -> impl Parser<'a, Located<Val>>
where
P: Parser<'a, Val>,
{
loc!(parser)
}

View file

@ -4,7 +4,7 @@ use parse::ast::Spaceable;
use parse::blankspace::{space0, space0_before};
use parse::collection::collection;
use parse::ident::unqualified_ident;
use parse::parser::{char, map_with_arena, optional, skip_first, Parser};
use parse::parser::{and, char, loc, map_with_arena, optional, skip_first, Parser};
use region::Located;
/// Parse a record - generally one of these two:
@ -30,29 +30,6 @@ where
)
}
/// For some reason, record() needs to use this instead of using the loc! macro directly.
#[inline(always)]
pub fn loc<'a, P, Val>(parser: P) -> impl Parser<'a, Located<Val>>
where
P: Parser<'a, Val>,
{
loc!(parser)
}
/// For some reason, record_field() needs to use this instead of using the and! macro directly.
#[inline(always)]
pub fn and<'a, P1, P2, A, B>(p1: P1, p2: P2) -> impl Parser<'a, (A, B)>
where
P1: Parser<'a, A>,
P2: Parser<'a, B>,
P1: 'a,
P2: 'a,
A: 'a,
B: 'a,
{
and!(p1, p2)
}
fn record_field<'a, P, S>(val_parser: P, min_indent: u16) -> impl Parser<'a, AssignedField<'a, S>>
where
P: Parser<'a, Located<S>>,