mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 04:08:19 +00:00
PNC for Patterns, stabilize formatting
This commit is contained in:
parent
bac165fd99
commit
3b0db07fa1
78 changed files with 789 additions and 332 deletions
|
@ -8,7 +8,7 @@
|
|||
|
||||
use roc_error_macros::internal_error;
|
||||
use roc_module::{called_via::CalledVia, symbol::Symbol};
|
||||
use roc_parse::ast::{self, Collection};
|
||||
use roc_parse::ast::{self, Collection, PatternApplyStyle};
|
||||
use roc_region::all::{Loc, Region};
|
||||
|
||||
use crate::{env::Env, pattern::Pattern, scope::Scope};
|
||||
|
@ -27,6 +27,7 @@ fn to_encoder<'a>(env: &mut Env<'a>, at_opaque: &'a str) -> ast::Expr<'a> {
|
|||
DERIVED_REGION,
|
||||
ast::Pattern::Identifier { ident: payload },
|
||||
)]),
|
||||
ast::PatternApplyStyle::Whitespace,
|
||||
);
|
||||
|
||||
// Encode.toEncoder payload
|
||||
|
@ -132,6 +133,7 @@ fn hash<'a>(env: &mut Env<'a>, at_opaque: &'a str) -> ast::Expr<'a> {
|
|||
DERIVED_REGION,
|
||||
ast::Pattern::Identifier { ident: payload },
|
||||
)]),
|
||||
PatternApplyStyle::Whitespace,
|
||||
);
|
||||
|
||||
// Hash.hash hasher payload
|
||||
|
@ -178,6 +180,7 @@ fn is_eq<'a>(env: &mut Env<'a>, at_opaque: &'a str) -> ast::Expr<'a> {
|
|||
DERIVED_REGION,
|
||||
ast::Pattern::Identifier { ident: payload1 },
|
||||
)]),
|
||||
PatternApplyStyle::Whitespace,
|
||||
);
|
||||
// \@Opaq payload2
|
||||
let opaque2 = ast::Pattern::Apply(
|
||||
|
@ -186,6 +189,7 @@ fn is_eq<'a>(env: &mut Env<'a>, at_opaque: &'a str) -> ast::Expr<'a> {
|
|||
DERIVED_REGION,
|
||||
ast::Pattern::Identifier { ident: payload2 },
|
||||
)]),
|
||||
PatternApplyStyle::Whitespace,
|
||||
);
|
||||
|
||||
// Bool.isEq payload1 payload2
|
||||
|
@ -232,6 +236,7 @@ fn to_inspector<'a>(env: &mut Env<'a>, at_opaque: &'a str) -> ast::Expr<'a> {
|
|||
DERIVED_REGION,
|
||||
ast::Pattern::Identifier { ident: payload },
|
||||
)]),
|
||||
PatternApplyStyle::Whitespace,
|
||||
);
|
||||
|
||||
// Inspect.toInspector payload
|
||||
|
|
|
@ -11,8 +11,9 @@ use roc_module::called_via::{BinOp, CalledVia};
|
|||
use roc_module::ident::ModuleName;
|
||||
use roc_parse::ast::Expr::{self, *};
|
||||
use roc_parse::ast::{
|
||||
is_expr_suffixed, AssignedField, Collection, Defs, ModuleImportParams, Pattern, ResultTryKind,
|
||||
StrLiteral, StrSegment, TryTarget, TypeAnnotation, ValueDef, WhenBranch,
|
||||
is_expr_suffixed, AssignedField, Collection, Defs, ModuleImportParams, Pattern,
|
||||
PatternApplyStyle, ResultTryKind, StrLiteral, StrSegment, TryTarget, TypeAnnotation, ValueDef,
|
||||
WhenBranch,
|
||||
};
|
||||
use roc_problem::can::Problem;
|
||||
use roc_region::all::{Loc, Region};
|
||||
|
@ -177,7 +178,11 @@ fn new_op_call_expr<'a>(
|
|||
env.arena.alloc(Loc::at(left.region, Pattern::Tag("Ok")));
|
||||
branch_1_patts.push(Loc::at(
|
||||
left.region,
|
||||
Pattern::Apply(branch_1_tag, branch_1_patts_args.into_bump_slice()),
|
||||
Pattern::Apply(
|
||||
branch_1_tag,
|
||||
branch_1_patts_args.into_bump_slice(),
|
||||
PatternApplyStyle::ParensAndCommas,
|
||||
),
|
||||
));
|
||||
let branch_one: &WhenBranch<'_> = env.arena.alloc(WhenBranch {
|
||||
patterns: branch_1_patts.into_bump_slice(),
|
||||
|
@ -198,7 +203,11 @@ fn new_op_call_expr<'a>(
|
|||
env.arena.alloc(Loc::at(left.region, Pattern::Tag("Err")));
|
||||
branch_2_patts.push(Loc::at(
|
||||
right.region,
|
||||
Pattern::Apply(branch_2_tag, branch_2_patts_args.into_bump_slice()),
|
||||
Pattern::Apply(
|
||||
branch_2_tag,
|
||||
branch_2_patts_args.into_bump_slice(),
|
||||
PatternApplyStyle::ParensAndCommas,
|
||||
),
|
||||
));
|
||||
let branch_two: &WhenBranch<'_> = env.arena.alloc(WhenBranch {
|
||||
patterns: branch_2_patts.into_bump_slice(),
|
||||
|
@ -1413,7 +1422,7 @@ fn desugar_pattern<'a>(env: &mut Env<'a>, scope: &mut Scope, pattern: Pattern<'a
|
|||
| MalformedIdent(_, _)
|
||||
| QualifiedIdentifier { .. } => pattern,
|
||||
|
||||
Apply(tag, arg_patterns) => {
|
||||
Apply(tag, arg_patterns, style) => {
|
||||
// Skip desugaring the tag, it should either be a Tag or OpaqueRef
|
||||
let mut desugared_arg_patterns = Vec::with_capacity_in(arg_patterns.len(), env.arena);
|
||||
for arg_pattern in arg_patterns.iter() {
|
||||
|
@ -1423,7 +1432,7 @@ fn desugar_pattern<'a>(env: &mut Env<'a>, scope: &mut Scope, pattern: Pattern<'a
|
|||
});
|
||||
}
|
||||
|
||||
Apply(tag, desugared_arg_patterns.into_bump_slice())
|
||||
Apply(tag, desugared_arg_patterns.into_bump_slice(), style)
|
||||
}
|
||||
RecordDestructure(field_patterns) => {
|
||||
RecordDestructure(desugar_record_destructures(env, scope, field_patterns))
|
||||
|
|
|
@ -411,7 +411,7 @@ pub fn canonicalize_pattern<'a>(
|
|||
)));
|
||||
Pattern::UnsupportedPattern(region)
|
||||
}
|
||||
Apply(tag, patterns) => {
|
||||
Apply(tag, patterns, _) => {
|
||||
let mut can_patterns = Vec::with_capacity(patterns.len());
|
||||
for loc_pattern in *patterns {
|
||||
let can_pattern = canonicalize_pattern(
|
||||
|
|
|
@ -78,6 +78,7 @@ Defs {
|
|||
ident: "name",
|
||||
},
|
||||
],
|
||||
Whitespace,
|
||||
),
|
||||
],
|
||||
value: @125-154 Apply(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue