mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
Parse opaque types
This commit is contained in:
parent
ab6019d402
commit
fa24e51593
13 changed files with 201 additions and 113 deletions
|
@ -2,7 +2,7 @@ use crate::annotation::{Formattable, Newlines, Parens};
|
|||
use crate::pattern::fmt_pattern;
|
||||
use crate::spaces::{fmt_spaces, INDENT};
|
||||
use crate::Buf;
|
||||
use roc_parse::ast::{TypeHeader, Def, Expr, Pattern};
|
||||
use roc_parse::ast::{Def, Expr, Pattern, TypeHeader};
|
||||
use roc_region::all::Loc;
|
||||
|
||||
/// A Located formattable value is also formattable
|
||||
|
@ -12,6 +12,7 @@ impl<'a> Formattable for Def<'a> {
|
|||
|
||||
match self {
|
||||
Alias { ann, .. } => ann.is_multiline(),
|
||||
Opaque { typ, .. } => typ.is_multiline(),
|
||||
Annotation(loc_pattern, loc_annotation) => {
|
||||
loc_pattern.is_multiline() || loc_annotation.is_multiline()
|
||||
}
|
||||
|
@ -60,6 +61,10 @@ impl<'a> Formattable for Def<'a> {
|
|||
Alias {
|
||||
header: TypeHeader { name, vars },
|
||||
ann,
|
||||
}
|
||||
| Opaque {
|
||||
header: TypeHeader { name, vars },
|
||||
typ: ann,
|
||||
} => {
|
||||
buf.indent(indent);
|
||||
buf.push_str(name.value);
|
||||
|
@ -69,7 +74,11 @@ impl<'a> Formattable for Def<'a> {
|
|||
fmt_pattern(buf, &var.value, indent, Parens::NotNeeded);
|
||||
}
|
||||
|
||||
buf.push_str(" :");
|
||||
buf.push_str(match self {
|
||||
Alias { .. } => " :",
|
||||
Opaque { .. } => " :=",
|
||||
_ => unreachable!(),
|
||||
});
|
||||
buf.spaces(1);
|
||||
|
||||
ann.format(buf, indent + INDENT)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue