diff --git a/sample.amo b/sample.amo index 92a8d71..ba7a5d6 100644 --- a/sample.amo +++ b/sample.amo @@ -2,9 +2,9 @@ type SimpleType = MyVariant1 - | MyVariant2 Integer[u32] - | MyVariant3 Integer[1..20] - | MyVariant4 Integer String + | MyVariant2 Int[u32] + | MyVariant3 Int[1..20] + | MyVariant4 Int String /* Multiline Comment! */ @@ -15,23 +15,24 @@ type Option val struct MyStruct = .field1 : SimpleType - .field2 : Integer + .field2 : Int trait Eq needs - add : Self, Self -> Self + .add : Self, Self -> Self trait Functor[a, b] on Self _ needs - map : (a -> b), Self a -> Self b - pure : a -> Self a + .map : (a -> b), Self a -> Self b + .pure : a -> Self a type ComplexType[a, b : Functor] = Left a | Right b impl Functor on Option _: - map mapper union = if union is + .map mapper union = if union is Some val -> Some (mapper val) None -> None + .pure elem = Some elem magnitude : Int, Int -> Int magnitude x y = sqrt (x * x) (y * y) @@ -43,7 +44,7 @@ soundeffect type = else "bop!" -destructure : MyStruct -> Option Integer +destructure : MyStruct -> Option Int destructure s = if s is MyStruct @@ -60,10 +61,23 @@ destructure s = None _ -> None -destructure_type : SimpleType -> Integer +destructure_type : SimpleType -> Int destructure_type t = if t is MyVariant1 -> 0 MyVariant2 x -> x * x MyVariant3 x -> x /2 MyVariant4 x _ -> x + +simple_tuple : (Int, Int) +simple_tuple = (1, 2) + +magnitude_plus_ten : Int, Int -> Int +magnitude_plus_ten x y = + let magnitude = + let x_squared = x * x + let y_squared = y * y + in sqrt (x + y) + in + let magnitude_plus_5 = magnitude + 5 + in magnitude_plus_5 + 5 diff --git a/src/token.rs b/src/token.rs index 25617e7..9347cad 100644 --- a/src/token.rs +++ b/src/token.rs @@ -90,6 +90,19 @@ pub enum Token { #[token("on")] On, + /// the `let` keyword + /// + /// Allows binding a value to an immutable variable that can be used multiple times + #[token("let")] + Let, + + /// the `in` keyword + /// + /// Used to seperate a series of `let` bindings from the expression they're being used + /// in. + #[token("in")] + In, + /// An `->` arrow /// /// Used as part of function type annotations as well as in the cases of If-Is blocks @@ -186,6 +199,18 @@ pub enum Token { #[token("..")] RangeOp, + /// A `.` period + /// + /// For getting fields of structs + #[token(".")] + Dot, + + /// A `,` comma + /// + /// The age-old and timeless delineator + #[token(",")] + Comma, + /// A newline NOT followed by whitespace /// /// This means that the following tokens are at the start of a line. For example