mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
Parse _ in type annotations as an 'Inferred' type
This commit is contained in:
parent
91c97dbba4
commit
7f5b873357
9 changed files with 64 additions and 1 deletions
|
@ -240,6 +240,9 @@ pub enum TypeAnnotation<'a> {
|
|||
tags: Collection<'a, Loc<Tag<'a>>>,
|
||||
},
|
||||
|
||||
/// '_', indicating the compiler should infer the type
|
||||
Inferred,
|
||||
|
||||
/// The `*` type variable, e.g. in (List *)
|
||||
Wildcard,
|
||||
|
||||
|
|
|
@ -626,6 +626,7 @@ pub enum EType<'a> {
|
|||
TApply(ETypeApply, Row, Col),
|
||||
TBadTypeVariable(Row, Col),
|
||||
TWildcard(Row, Col),
|
||||
TInferred(Row, Col),
|
||||
///
|
||||
TStart(Row, Col),
|
||||
TEnd(Row, Col),
|
||||
|
|
|
@ -55,6 +55,7 @@ fn term<'a>(min_indent: u16) -> impl Parser<'a, Located<TypeAnnotation<'a>>, ETy
|
|||
and!(
|
||||
one_of!(
|
||||
loc_wildcard(),
|
||||
loc_inferred(),
|
||||
specialize(EType::TInParens, loc_type_in_parens(min_indent)),
|
||||
loc!(specialize(EType::TRecord, record_type(min_indent))),
|
||||
loc!(specialize(EType::TTagUnion, tag_union_type(min_indent))),
|
||||
|
@ -111,6 +112,15 @@ fn loc_wildcard<'a>() -> impl Parser<'a, Located<TypeAnnotation<'a>>, EType<'a>>
|
|||
})
|
||||
}
|
||||
|
||||
/// The `_` indicating an inferred type, e.g. in (List _)
|
||||
fn loc_inferred<'a>() -> impl Parser<'a, Located<TypeAnnotation<'a>>, EType<'a>> {
|
||||
map!(loc!(word1(b'_', EType::TInferred)), |loc_val: Located<
|
||||
(),
|
||||
>| {
|
||||
loc_val.map(|_| TypeAnnotation::Inferred)
|
||||
})
|
||||
}
|
||||
|
||||
fn loc_applied_arg<'a>(min_indent: u16) -> impl Parser<'a, Located<TypeAnnotation<'a>>, EType<'a>> {
|
||||
use crate::ast::Spaceable;
|
||||
|
||||
|
@ -119,6 +129,7 @@ fn loc_applied_arg<'a>(min_indent: u16) -> impl Parser<'a, Located<TypeAnnotatio
|
|||
backtrackable(space0_e(min_indent, EType::TSpace, EType::TIndentStart)),
|
||||
one_of!(
|
||||
loc_wildcard(),
|
||||
loc_inferred(),
|
||||
specialize(EType::TInParens, loc_type_in_parens(min_indent)),
|
||||
loc!(specialize(EType::TRecord, record_type(min_indent))),
|
||||
loc!(specialize(EType::TTagUnion, tag_union_type(min_indent))),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue