mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
move in parens over
This commit is contained in:
parent
aa75094c53
commit
a1d72fd74d
1 changed files with 32 additions and 12 deletions
|
@ -2,8 +2,8 @@ use crate::ast::{
|
||||||
AssignedField, Attempting, CommentOrNewline, Def, Expr, Pattern, Spaceable, TypeAnnotation,
|
AssignedField, Attempting, CommentOrNewline, Def, Expr, Pattern, Spaceable, TypeAnnotation,
|
||||||
};
|
};
|
||||||
use crate::blankspace::{
|
use crate::blankspace::{
|
||||||
line_comment, space0, space0_after, space0_after_e, space0_around, space0_around_ee,
|
line_comment, space0, space0_after, space0_after_e, space0_around_ee, space0_before,
|
||||||
space0_before, space0_before_e, space0_e, space1, space1_before, spaces_exactly,
|
space0_before_e, space0_e, space1, space1_before, spaces_exactly,
|
||||||
};
|
};
|
||||||
use crate::ident::{ident, lowercase_ident, Ident};
|
use crate::ident::{ident, lowercase_ident, Ident};
|
||||||
use crate::keyword;
|
use crate::keyword;
|
||||||
|
@ -11,8 +11,8 @@ use crate::number_literal::number_literal;
|
||||||
use crate::parser::{
|
use crate::parser::{
|
||||||
self, allocated, and_then_with_indent_level, ascii_char, ascii_string, attempt, backtrackable,
|
self, allocated, and_then_with_indent_level, ascii_char, ascii_string, attempt, backtrackable,
|
||||||
fail, map, newline_char, not, not_followed_by, optional, sep_by1, sep_by1_e, specialize,
|
fail, map, newline_char, not, not_followed_by, optional, sep_by1, sep_by1_e, specialize,
|
||||||
specialize_ref, then, unexpected, unexpected_eof, word1, word2, EExpr, ELambda, Either, If,
|
specialize_ref, then, unexpected, unexpected_eof, word1, word2, EExpr, EInParens, ELambda,
|
||||||
List, ParseResult, Parser, State, SyntaxError, When,
|
Either, If, List, ParseResult, Parser, State, SyntaxError, When,
|
||||||
};
|
};
|
||||||
use crate::pattern::loc_closure_param;
|
use crate::pattern::loc_closure_param;
|
||||||
use crate::type_annotation;
|
use crate::type_annotation;
|
||||||
|
@ -29,17 +29,38 @@ pub fn expr<'a>(min_indent: u16) -> impl Parser<'a, Expr<'a>, SyntaxError<'a>> {
|
||||||
move |arena, state: State<'a>| parse_expr(min_indent, arena, state)
|
move |arena, state: State<'a>| parse_expr(min_indent, arena, state)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn loc_expr_in_parens<'a>(min_indent: u16) -> impl Parser<'a, Located<Expr<'a>>, SyntaxError<'a>> {
|
||||||
|
specialize(
|
||||||
|
|e, r, c| SyntaxError::Expr(EExpr::InParens(e, r, c)),
|
||||||
|
loc_expr_in_parens_help(min_indent),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn loc_expr_in_parens_help<'a>(
|
||||||
|
min_indent: u16,
|
||||||
|
) -> impl Parser<'a, Located<Expr<'a>>, EInParens<'a>> {
|
||||||
|
between!(
|
||||||
|
word1(b'(', EInParens::Open),
|
||||||
|
space0_around_ee(
|
||||||
|
specialize_ref(
|
||||||
|
EInParens::Syntax,
|
||||||
|
loc!(move |arena, state| parse_expr(min_indent, arena, state))
|
||||||
|
),
|
||||||
|
min_indent,
|
||||||
|
EInParens::Space,
|
||||||
|
EInParens::IndentOpen,
|
||||||
|
EInParens::IndentEnd,
|
||||||
|
),
|
||||||
|
word1(b')', EInParens::End)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! loc_parenthetical_expr {
|
macro_rules! loc_parenthetical_expr {
|
||||||
($min_indent:expr, $args_parser:expr) => {
|
($min_indent:expr, $args_parser:expr) => {
|
||||||
then(
|
then(
|
||||||
loc!(and!(
|
loc!(and!(
|
||||||
between!(
|
|
||||||
ascii_char(b'(' ),
|
|
||||||
map_with_arena!(
|
map_with_arena!(
|
||||||
space0_around(
|
loc_expr_in_parens($min_indent),
|
||||||
loc!(move |arena, state| parse_expr($min_indent, arena, state)),
|
|
||||||
$min_indent,
|
|
||||||
),
|
|
||||||
|arena: &'a Bump, loc_expr: Located<Expr<'a>>| {
|
|arena: &'a Bump, loc_expr: Located<Expr<'a>>| {
|
||||||
Located {
|
Located {
|
||||||
region: loc_expr.region,
|
region: loc_expr.region,
|
||||||
|
@ -47,8 +68,7 @@ macro_rules! loc_parenthetical_expr {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
ascii_char(b')' )
|
|
||||||
),
|
|
||||||
optional(either!(
|
optional(either!(
|
||||||
// There may optionally be function args after the ')'
|
// There may optionally be function args after the ')'
|
||||||
// e.g. ((foo bar) baz)
|
// e.g. ((foo bar) baz)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue