Un-macro between

This commit is contained in:
Jackson Wambolt 2024-04-14 21:34:32 -05:00
parent 8a144149e2
commit 60fa7ebe9e
No known key found for this signature in database
GPG key ID: 76F29A42FEE8811C
3 changed files with 19 additions and 21 deletions

View file

@ -10,10 +10,10 @@ use crate::blankspace::{
use crate::ident::{integer_ident, lowercase_ident, parse_ident, Accessor, Ident}; use crate::ident::{integer_ident, lowercase_ident, parse_ident, Accessor, Ident};
use crate::keyword; use crate::keyword;
use crate::parser::{ use crate::parser::{
self, backtrackable, byte, byte_indent, increment_min_indent, line_min_indent, optional, self, backtrackable, between, byte, byte_indent, increment_min_indent, line_min_indent,
reset_min_indent, sep_by1, sep_by1_e, set_min_indent, skip_first, skip_second, specialize_err, optional, reset_min_indent, sep_by1, sep_by1_e, set_min_indent, skip_first, skip_second,
specialize_err_ref, then, two_bytes, EClosure, EExpect, EExpr, EIf, EInParens, EList, ENumber, specialize_err, specialize_err_ref, then, two_bytes, EClosure, EExpect, EExpr, EIf, EInParens,
EPattern, ERecord, EString, EType, EWhen, Either, ParseResult, Parser, EList, ENumber, EPattern, ERecord, EString, EType, EWhen, Either, ParseResult, Parser,
}; };
use crate::pattern::{closure_param, loc_implements_parser}; use crate::pattern::{closure_param, loc_implements_parser};
use crate::state::State; use crate::state::State;
@ -3068,7 +3068,7 @@ struct RecordHelp<'a> {
} }
fn record_help<'a>() -> impl Parser<'a, RecordHelp<'a>, ERecord<'a>> { fn record_help<'a>() -> impl Parser<'a, RecordHelp<'a>, ERecord<'a>> {
between!( between(
byte(b'{', ERecord::Open), byte(b'{', ERecord::Open),
reset_min_indent(record!(RecordHelp { reset_min_indent(record!(RecordHelp {
// You can optionally have an identifier followed by an '&' to // You can optionally have an identifier followed by an '&' to
@ -3089,7 +3089,7 @@ fn record_help<'a>() -> impl Parser<'a, RecordHelp<'a>, ERecord<'a>> {
RecordField::SpaceBefore RecordField::SpaceBefore
), ),
})), })),
byte(b'}', ERecord::End) byte(b'}', ERecord::End),
) )
} }

View file

@ -1502,14 +1502,14 @@ macro_rules! collection_inner {
#[macro_export] #[macro_export]
macro_rules! collection_trailing_sep_e { macro_rules! collection_trailing_sep_e {
($opening_brace:expr, $elem:expr, $delimiter:expr, $closing_brace:expr, $space_before:expr) => { ($opening_brace:expr, $elem:expr, $delimiter:expr, $closing_brace:expr, $space_before:expr) => {
between!( $crate::parser::between(
$opening_brace, $opening_brace,
$crate::parser::reset_min_indent($crate::collection_inner!( $crate::parser::reset_min_indent($crate::collection_inner!(
$elem, $elem,
$delimiter, $delimiter,
$space_before $space_before
)), )),
$closing_brace $closing_brace,
) )
}; };
} }
@ -2524,7 +2524,7 @@ macro_rules! either {
/// # } /// # }
/// # let arena = Bump::new(); /// # let arena = Bump::new();
/// # fn foo<'a>(arena: &'a Bump) { /// # fn foo<'a>(arena: &'a Bump) {
/// let parser = between!( /// let parser = between(
/// byte(b'(', Problem::NotFound), /// byte(b'(', Problem::NotFound),
/// word("hello", Problem::NotFound), /// word("hello", Problem::NotFound),
/// byte(b')', Problem::NotFound) /// byte(b')', Problem::NotFound)
@ -2536,14 +2536,12 @@ macro_rules! either {
/// # } /// # }
/// # foo(&arena); /// # foo(&arena);
/// ``` /// ```
#[macro_export] pub fn between<'a, Before, Inner, After, Err: 'a>(
macro_rules! between { opening_brace: impl Parser<'a, Before, Err>,
($opening_brace:expr, $parser:expr, $closing_brace:expr) => { inner: impl Parser<'a, Inner, Err>,
$crate::parser::skip_first( closing_brace: impl Parser<'a, After, Err>,
$opening_brace, ) -> impl Parser<'a, Inner, Err> {
$crate::parser::skip_second($parser, $closing_brace), skip_first(opening_brace, skip_second(inner, closing_brace))
)
};
} }
/// Runs two parsers in succession. If both parsers succeed, the output is a tuple of both outputs. /// Runs two parsers in succession. If both parsers succeed, the output is a tuple of both outputs.

View file

@ -2,8 +2,8 @@ use crate::ast::{EscapedChar, SingleQuoteLiteral, StrLiteral, StrSegment};
use crate::expr; use crate::expr;
use crate::parser::Progress::{self, *}; use crate::parser::Progress::{self, *};
use crate::parser::{ use crate::parser::{
allocated, byte, loc, reset_min_indent, skip_second, specialize_err_ref, then, BadInputError, allocated, between, byte, loc, reset_min_indent, skip_second, specialize_err_ref, then,
ESingleQuote, EString, Parser, BadInputError, ESingleQuote, EString, Parser,
}; };
use crate::state::State; use crate::state::State;
use bumpalo::collections::vec::Vec; use bumpalo::collections::vec::Vec;
@ -403,10 +403,10 @@ pub fn parse_str_like_literal<'a>() -> impl Parser<'a, StrLikeLiteral<'a>, EStri
// Parse the hex digits, surrounded by parens, then // Parse the hex digits, surrounded by parens, then
// give a canonicalization error if the digits form // give a canonicalization error if the digits form
// an invalid unicode code point. // an invalid unicode code point.
let (_progress, loc_digits, new_state) = between!( let (_progress, loc_digits, new_state) = between(
byte(b'(', EString::CodePtOpen), byte(b'(', EString::CodePtOpen),
loc(ascii_hex_digits()), loc(ascii_hex_digits()),
byte(b')', EString::CodePtEnd) byte(b')', EString::CodePtEnd),
) )
.parse(arena, state, min_indent)?; .parse(arena, state, min_indent)?;