mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
Implement return keyword
This commit is contained in:
parent
20a539a96d
commit
b3e60f9d3a
39 changed files with 594 additions and 80 deletions
|
@ -423,6 +423,7 @@ impl<'a> Formattable for ValueDef<'a> {
|
|||
ModuleImport(module_import) => module_import.is_multiline(),
|
||||
IngestedFileImport(ingested_file_import) => ingested_file_import.is_multiline(),
|
||||
Stmt(loc_expr) => loc_expr.is_multiline(),
|
||||
Return(loc_expr) => loc_expr.is_multiline(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -464,6 +465,7 @@ impl<'a> Formattable for ValueDef<'a> {
|
|||
ModuleImport(module_import) => module_import.format(buf, indent),
|
||||
IngestedFileImport(ingested_file_import) => ingested_file_import.format(buf, indent),
|
||||
Stmt(loc_expr) => loc_expr.format_with_options(buf, parens, newlines, indent),
|
||||
Return(loc_expr) => loc_expr.format_with_options(buf, parens, newlines, indent),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ use roc_parse::ast::{
|
|||
};
|
||||
use roc_parse::ast::{StrLiteral, StrSegment};
|
||||
use roc_parse::ident::Accessor;
|
||||
use roc_parse::keyword;
|
||||
use roc_region::all::Loc;
|
||||
|
||||
impl<'a> Formattable for Expr<'a> {
|
||||
|
@ -70,6 +71,9 @@ impl<'a> Formattable for Expr<'a> {
|
|||
LowLevelDbg(_, _, _) => unreachable!(
|
||||
"LowLevelDbg should only exist after desugaring, not during formatting"
|
||||
),
|
||||
Return(return_value, after_return) => {
|
||||
return_value.is_multiline() || after_return.is_some()
|
||||
}
|
||||
|
||||
If {
|
||||
if_thens: branches,
|
||||
|
@ -452,6 +456,9 @@ impl<'a> Formattable for Expr<'a> {
|
|||
LowLevelDbg(_, _, _) => unreachable!(
|
||||
"LowLevelDbg should only exist after desugaring, not during formatting"
|
||||
),
|
||||
Return(return_value, after_return) => {
|
||||
fmt_return(buf, return_value, &after_return, parens, newlines, indent);
|
||||
}
|
||||
If {
|
||||
if_thens: branches,
|
||||
final_else,
|
||||
|
@ -1064,6 +1071,27 @@ fn fmt_expect<'a>(
|
|||
continuation.format(buf, indent);
|
||||
}
|
||||
|
||||
fn fmt_return<'a>(
|
||||
buf: &mut Buf,
|
||||
return_value: &'a Loc<Expr<'a>>,
|
||||
after_return: &Option<&'a Loc<Expr<'a>>>,
|
||||
parens: Parens,
|
||||
newlines: Newlines,
|
||||
indent: u16,
|
||||
) {
|
||||
buf.ensure_ends_with_newline();
|
||||
buf.indent(indent);
|
||||
buf.push_str(keyword::RETURN);
|
||||
|
||||
buf.spaces(1);
|
||||
|
||||
return_value.format(buf, indent);
|
||||
|
||||
if let Some(after_return) = after_return {
|
||||
after_return.format_with_options(buf, parens, newlines, indent);
|
||||
}
|
||||
}
|
||||
|
||||
fn fmt_if<'a>(
|
||||
buf: &mut Buf,
|
||||
branches: &'a [(Loc<Expr<'a>>, Loc<Expr<'a>>)],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue