Type annos

This commit is contained in:
Greg Shuflin 2021-11-11 19:01:16 -08:00
parent 8c48f63a2d
commit fbb0269623
2 changed files with 7 additions and 7 deletions

View File

@ -109,10 +109,10 @@ peg::parser! {
alias:identifier() _ "=" _ name:identifier() { Declaration::TypeAlias { alias: rc_string(alias), original: rc_string(name), } } alias:identifier() _ "=" _ name:identifier() { Declaration::TypeAlias { alias: rc_string(alias), original: rc_string(name), } }
rule type_anno() -> TypeIdentifier = rule type_anno() -> TypeIdentifier =
":" _ ident:identifier() { TypeIdentifier::Singleton(TypeSingletonName { name: Rc::new(ident.to_string()), params: vec![] }) } ":" _ identifier:type_identifier() { identifier }
pub rule expression() -> Expression = pub rule expression() -> Expression =
_ kind:expression_kind() { Expression { id: Default::default(), type_anno: None, kind: kind } } _ kind:expression_kind() _ type_anno:type_anno()? { Expression { id: Default::default(), type_anno, kind: kind } }
rule expression_no_struct() -> Expression = rule expression_no_struct() -> Expression =
_ kind:expression_kind_no_struct() { Expression { id: Default::default(), type_anno: None, kind: kind } } _ kind:expression_kind_no_struct() { Expression { id: Default::default(), type_anno: None, kind: kind } }

View File

@ -547,7 +547,7 @@ fn type_annotations() {
use ExpressionKind::*; use ExpressionKind::*;
use TypeIdentifier::*; use TypeIdentifier::*;
assert_ast!( assert_ast2!(
"let a = b : Int", "let a = b : Int",
vec![decl(Declaration::Binding { vec![decl(Declaration::Binding {
name: rc("a"), name: rc("a"),
@ -557,11 +557,11 @@ fn type_annotations() {
})] })]
); );
assert_expr!( assert_expr2!(
"a: Int", "a: Int",
expr_anno(Value(qn!(a)), Singleton(TypeSingletonName { name: rc("Int"), params: vec![] })) expr_anno(Value(qn!(a)), Singleton(TypeSingletonName { name: rc("Int"), params: vec![] }))
); );
assert_expr!( assert_expr2!(
"a: Option<Int>", "a: Option<Int>",
expr_anno( expr_anno(
Value(qn!(a)), Value(qn!(a)),
@ -571,7 +571,7 @@ fn type_annotations() {
}) })
) )
); );
assert_expr!( assert_expr2!(
"a: KoreanBBQSpecifier<Kimchi, Option<Bulgogi> >", "a: KoreanBBQSpecifier<Kimchi, Option<Bulgogi> >",
expr_anno( expr_anno(
Value(qn!(a)), Value(qn!(a)),
@ -587,7 +587,7 @@ fn type_annotations() {
}) })
) )
); );
assert_expr!( assert_expr2!(
"a: (Int, Yolo<a>)", "a: (Int, Yolo<a>)",
expr_anno( expr_anno(
Value(qn!(a)), Value(qn!(a)),