mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 19:58:18 +00:00
Un-macro between
This commit is contained in:
parent
8a144149e2
commit
60fa7ebe9e
3 changed files with 19 additions and 21 deletions
|
@ -10,10 +10,10 @@ use crate::blankspace::{
|
|||
use crate::ident::{integer_ident, lowercase_ident, parse_ident, Accessor, Ident};
|
||||
use crate::keyword;
|
||||
use crate::parser::{
|
||||
self, backtrackable, byte, byte_indent, increment_min_indent, line_min_indent, optional,
|
||||
reset_min_indent, sep_by1, sep_by1_e, set_min_indent, skip_first, skip_second, specialize_err,
|
||||
specialize_err_ref, then, two_bytes, EClosure, EExpect, EExpr, EIf, EInParens, EList, ENumber,
|
||||
EPattern, ERecord, EString, EType, EWhen, Either, ParseResult, Parser,
|
||||
self, backtrackable, between, byte, byte_indent, increment_min_indent, line_min_indent,
|
||||
optional, reset_min_indent, sep_by1, sep_by1_e, set_min_indent, skip_first, skip_second,
|
||||
specialize_err, specialize_err_ref, then, two_bytes, EClosure, EExpect, EExpr, EIf, EInParens,
|
||||
EList, ENumber, EPattern, ERecord, EString, EType, EWhen, Either, ParseResult, Parser,
|
||||
};
|
||||
use crate::pattern::{closure_param, loc_implements_parser};
|
||||
use crate::state::State;
|
||||
|
@ -3068,7 +3068,7 @@ struct RecordHelp<'a> {
|
|||
}
|
||||
|
||||
fn record_help<'a>() -> impl Parser<'a, RecordHelp<'a>, ERecord<'a>> {
|
||||
between!(
|
||||
between(
|
||||
byte(b'{', ERecord::Open),
|
||||
reset_min_indent(record!(RecordHelp {
|
||||
// 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
|
||||
),
|
||||
})),
|
||||
byte(b'}', ERecord::End)
|
||||
byte(b'}', ERecord::End),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -1502,14 +1502,14 @@ macro_rules! collection_inner {
|
|||
#[macro_export]
|
||||
macro_rules! collection_trailing_sep_e {
|
||||
($opening_brace:expr, $elem:expr, $delimiter:expr, $closing_brace:expr, $space_before:expr) => {
|
||||
between!(
|
||||
$crate::parser::between(
|
||||
$opening_brace,
|
||||
$crate::parser::reset_min_indent($crate::collection_inner!(
|
||||
$elem,
|
||||
$delimiter,
|
||||
$space_before
|
||||
)),
|
||||
$closing_brace
|
||||
$closing_brace,
|
||||
)
|
||||
};
|
||||
}
|
||||
|
@ -2524,7 +2524,7 @@ macro_rules! either {
|
|||
/// # }
|
||||
/// # let arena = Bump::new();
|
||||
/// # fn foo<'a>(arena: &'a Bump) {
|
||||
/// let parser = between!(
|
||||
/// let parser = between(
|
||||
/// byte(b'(', Problem::NotFound),
|
||||
/// word("hello", Problem::NotFound),
|
||||
/// byte(b')', Problem::NotFound)
|
||||
|
@ -2536,14 +2536,12 @@ macro_rules! either {
|
|||
/// # }
|
||||
/// # foo(&arena);
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! between {
|
||||
($opening_brace:expr, $parser:expr, $closing_brace:expr) => {
|
||||
$crate::parser::skip_first(
|
||||
$opening_brace,
|
||||
$crate::parser::skip_second($parser, $closing_brace),
|
||||
)
|
||||
};
|
||||
pub fn between<'a, Before, Inner, After, Err: 'a>(
|
||||
opening_brace: impl Parser<'a, Before, Err>,
|
||||
inner: impl Parser<'a, Inner, Err>,
|
||||
closing_brace: impl Parser<'a, After, Err>,
|
||||
) -> impl Parser<'a, Inner, Err> {
|
||||
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.
|
||||
|
|
|
@ -2,8 +2,8 @@ use crate::ast::{EscapedChar, SingleQuoteLiteral, StrLiteral, StrSegment};
|
|||
use crate::expr;
|
||||
use crate::parser::Progress::{self, *};
|
||||
use crate::parser::{
|
||||
allocated, byte, loc, reset_min_indent, skip_second, specialize_err_ref, then, BadInputError,
|
||||
ESingleQuote, EString, Parser,
|
||||
allocated, between, byte, loc, reset_min_indent, skip_second, specialize_err_ref, then,
|
||||
BadInputError, ESingleQuote, EString, Parser,
|
||||
};
|
||||
use crate::state::State;
|
||||
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
|
||||
// give a canonicalization error if the digits form
|
||||
// an invalid unicode code point.
|
||||
let (_progress, loc_digits, new_state) = between!(
|
||||
let (_progress, loc_digits, new_state) = between(
|
||||
byte(b'(', EString::CodePtOpen),
|
||||
loc(ascii_hex_digits()),
|
||||
byte(b')', EString::CodePtEnd)
|
||||
byte(b')', EString::CodePtEnd),
|
||||
)
|
||||
.parse(arena, state, min_indent)?;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue