aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCamil Staps2023-02-01 21:22:23 +0100
committerCamil Staps2023-02-01 21:22:23 +0100
commit4ba55277a99542d245568da989b5217b04262f26 (patch)
treeba6b4ed2d1da9a1c46256fd58f126ef387512ed5
parentUse <<|> instead of <|> in parser to reduce memory usage (diff)
Remove ambiguity from function definition syntax: Type (x y) could have Type as kind *->*, or (x y) could be the rhs
-rw-r--r--doc/docs/frontend/syntax.md12
-rw-r--r--example.txt30
-rw-r--r--snug-clean/src/Snug/Parse.icl2
3 files changed, 22 insertions, 22 deletions
diff --git a/doc/docs/frontend/syntax.md b/doc/docs/frontend/syntax.md
index 836201c..17436af 100644
--- a/doc/docs/frontend/syntax.md
+++ b/doc/docs/frontend/syntax.md
@@ -40,19 +40,19 @@ Type synonyms can be defined with:
## Functions
```snug
-(fun length ((xs : List a)) : Int
- (length_acc 0 xs))
+(fun length ((xs : List a)) : Int :
+ length_acc 0 xs)
-(fun length_acc ((n : Int) (xs : List a)) : Int
- (case xs (
+(fun length_acc ((n : Int) (xs : List a)) : Int :
+ case xs (
(Nil -> n)
- (Cons _ xs -> length_acc (+ n 1) xs))))
+ (Cons _ xs -> length_acc (+ n 1) xs)))
```
In abstract terms, the syntax is:
```snug
-(fun NAME (ARGUMENTS) : TYPE (EXPRESSION))
+(fun NAME (ARGUMENTS) : TYPE : EXPRESSION)
```
where arguments are of the form `(NAME : TYPE)`.
diff --git a/example.txt b/example.txt
index 26fc2d8..5aa858a 100644
--- a/example.txt
+++ b/example.txt
@@ -41,15 +41,15 @@
(DataDef TypeIdent (List TypeVarIdent) (List ConstructorDef))
(FunDef SymbolIdent (List (Tuple SymbolIdent Type)) Type Expression)))
-(fun list_ast () : Definition
- (DataDef
+(fun list_ast () : Definition :
+ DataDef
(Cons 'L' (Cons 'i' (Cons 's' (Cons 't' Nil))))
(Cons (Cons 'a' Nil) Nil)
(Cons (ConstructorDef (Cons 'N' (Cons 'i' (Cons 'l' Nil))) Nil)
(Cons (ConstructorDef (Cons 'C' (Cons 'o' (Cons 'n' (Cons 's' Nil)))) (Cons (TypeVar (Cons 'a' Nil)) (Cons (TypeApp (Type (Cons 'L' (Cons 'i' (Cons 's' (Cons 't' Nil))))) (TypeVar (Cons 'a' Nil))) Nil)))
- Nil))))
-(fun length_acc_ast () : Definition
- (FunDef
+ Nil)))
+(fun length_acc_ast () : Definition :
+ FunDef
(Cons 'l' (Cons 'e' (Cons 'n' (Cons 'g' (Cons 't' (Cons 'h' (Cons '_' (Cons 'a' (Cons 'c' (Cons 'c' Nil))))))))))
(Cons (Tuple (Cons 'n' Nil) (Type (Cons 'I' (Cons 'n' (Cons 't' Nil)))))
(Cons (Tuple (Cons 'x' (Cons 's' Nil)) (TypeApp (Type (Cons 'L' (Cons 'i' (Cons 's' (Cons 't' Nil))))) (TypeVar (Cons 'a' Nil))))
@@ -62,18 +62,18 @@
(Cons (CaseAlternative
(ConstructorPattern (Cons 'C' (Cons 'o' (Cons 'n' (Cons 's' Nil)))) (Cons Wildcard (Cons (IdentPattern (Cons 'x' (Cons 's' Nil))) Nil)))
(ExpApp (ExpApp (Symbol (Cons 'l' (Cons 'e' (Cons 'n' (Cons 'g' (Cons 't' (Cons 'h' (Cons '_' (Cons 'a' (Cons 'c' (Cons 'c' Nil))))))))))) (ExpApp (ExpApp (Cons '+' Nil) (Cons 'n' Nil)) (BasicValue (BVInt 1)))) (Cons 'x' (Cons 's' Nil))))
- Nil)))))
+ Nil))))
(#
-(fun length ((xs : List a)) : Int
- (length_acc 0 xs))
-(fun length_acc ((n : Int) (xs : List a)) : Int
- (case xs (
+(fun length ((xs : List a)) : Int :
+ length_acc 0 xs)
+(fun length_acc ((n : Int) (xs : List a)) : Int :
+ case xs (
(Nil -> n)
- (Cons _ xs -> length_acc (+ n 1) xs))))
+ (Cons _ xs -> length_acc (+ n 1) xs)))
#)
-(fun testb ((x : Int) (y : Int)) : Int
- (Tuple 37 'a'))
-(fun test () : Int
- (testb 37 42))
+(fun testb ((x : Int) (y : Int)) : Int :
+ Tuple 37 'a')
+(fun test () : Int :
+ testb 37 42)
diff --git a/snug-clean/src/Snug/Parse.icl b/snug-clean/src/Snug/Parse.icl
index 64331c5..9d58f23 100644
--- a/snug-clean/src/Snug/Parse.icl
+++ b/snug-clean/src/Snug/Parse.icl
@@ -42,7 +42,7 @@ where
(pToken (TIdent "fun") *> symbolIdent)
(simpleList (parenthesized typedArgument))
(pToken TColon *> type)
- simpleOrParenthesizedExpression
+ (pToken TColon *> expression)
simpleConstructorDef = liftM2 ConstructorDef constructorIdent (pure [])
constructorDef = liftM2 ConstructorDef constructorIdent (many simpleOrParenthesizedType)