summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/LambdaCube/Compiler/Parser.hs40
-rw-r--r--testdata/language-features/basic-list/list05.reject.out2
-rw-r--r--testdata/language-features/basic-list/list06.reject.out2
-rw-r--r--testdata/language-features/basic-values/def05.reject.out2
-rw-r--r--testdata/language-features/basic-values/def06.reject.out2
-rw-r--r--testdata/language-features/basic-values/redefine03.reject.out2
-rw-r--r--testdata/listcompr01.reject.out2
7 files changed, 33 insertions, 19 deletions
diff --git a/src/LambdaCube/Compiler/Parser.hs b/src/LambdaCube/Compiler/Parser.hs
index e7356653..dd196ae6 100644
--- a/src/LambdaCube/Compiler/Parser.hs
+++ b/src/LambdaCube/Compiler/Parser.hs
@@ -157,6 +157,9 @@ pattern SLabelEnd a = SBuiltin "labelend" `SAppV` a
157 157
158pattern SBuiltin s <- SGlobal (_, s) where SBuiltin s = SGlobal (debugSI $ "builtin " ++ s, s) 158pattern SBuiltin s <- SGlobal (_, s) where SBuiltin s = SGlobal (debugSI $ "builtin " ++ s, s)
159 159
160pattern LeftSection op e = SBuiltin "^leftSection" `SAppV` SGlobal op `SAppV` e
161pattern RightSection e op = SBuiltin "^rightSection" `SAppV` e `SAppV` SGlobal op
162
160sApp v a b = SApp (sourceInfo a <> sourceInfo b) v a b 163sApp v a b = SApp (sourceInfo a <> sourceInfo b) v a b
161sBind v x a b = SBind (sourceInfo a <> sourceInfo b) v x a b 164sBind v x a b = SBind (sourceInfo a <> sourceInfo b) v x a b
162 165
@@ -369,13 +372,9 @@ parseTerm prec = withRange setSI $ case prec of
369 option t $ mkPi <$> (Visible <$ reservedOp "->" <|> Hidden <$ reservedOp "=>") <*> pure t <*> parseTTerm PrecLam 372 option t $ mkPi <$> (Visible <$ reservedOp "->" <|> Hidden <$ reservedOp "=>") <*> pure t <*> parseTTerm PrecLam
370 PrecEq -> parseTerm PrecAnn >>= \t -> option t $ SAppV2 (SBuiltin "'EqCT" `SAppV` SType) t <$ reservedOp "~" <*> parseTTerm PrecAnn 373 PrecEq -> parseTerm PrecAnn >>= \t -> option t $ SAppV2 (SBuiltin "'EqCT" `SAppV` SType) t <$ reservedOp "~" <*> parseTTerm PrecAnn
371 PrecAnn -> parseTerm PrecOp >>= \t -> option t $ SAnn t <$> parseType Nothing 374 PrecAnn -> parseTerm PrecOp >>= \t -> option t $ SAnn t <$> parseType Nothing
372 PrecOp -> calculatePrecs <$> dsInfo <*> p' where 375 PrecOp -> join $ calculatePrecs <$> namespace <*> dsInfo <*> some item where
373 p' = (\ns op (t, xs) -> (mkNat ns 0, (op, t): xs)) <$> namespace <*> parseSIName ("-" <$ reservedOp "-") <*> p_ 376 item = Right <$> parseTerm PrecApp
374 <|> p_ 377 <|> Left <$> parseSIName operatorT
375 p_ = (,) <$> parseTerm PrecApp <*> option [] (parseSIName operatorT >>= p)
376 p op = do (exp, op') <- try "expression" ((,) <$> parseTerm PrecApp <*> parseSIName operatorT)
377 ((op, exp):) <$> p op'
378 <|> pure . (,) op <$> parseTerm PrecLam
379 PrecApp -> 378 PrecApp ->
380 try "" {- TODO: adjust try for better error messages e.g. don't use braces -} 379 try "" {- TODO: adjust try for better error messages e.g. don't use braces -}
381 (apps' <$> sVar upperCase <*> braces (commaSep $ lowerCase *> reservedOp "=" *> ((,) Visible <$> parseTerm PrecLam))) 380 (apps' <$> sVar upperCase <*> braces (commaSep $ lowerCase *> reservedOp "=" *> ((,) Visible <$> parseTerm PrecLam)))
@@ -398,17 +397,12 @@ parseTerm prec = withRange setSI $ case prec of
398 <|> mkDotDot <$> try "dotdot expression" (reservedOp "[" *> parseTerm PrecLam <* reservedOp ".." ) <*> parseTerm PrecLam <* reservedOp "]" 397 <|> mkDotDot <$> try "dotdot expression" (reservedOp "[" *> parseTerm PrecLam <* reservedOp ".." ) <*> parseTerm PrecLam <* reservedOp "]"
399 <|> (dsInfo >>= listCompr) 398 <|> (dsInfo >>= listCompr)
400 <|> mkList <$> namespace <*> brackets (commaSep $ parseTerm PrecLam) 399 <|> mkList <$> namespace <*> brackets (commaSep $ parseTerm PrecLam)
401 <|> mkLeftSection <$> try "left section"{-todo: better try-} (parens $ (,) <$> parseSIName (mfilter (/= "-") operatorT) <*> parseTerm PrecLam)
402 <|> mkRightSection <$> try "right section"{-todo: better try!-} (parens $ (,) <$> parseTerm PrecApp <*> parseSIName operatorT)
403 <|> mkTuple <$> namespace <*> parens (commaSep $ parseTerm PrecLam) 400 <|> mkTuple <$> namespace <*> parens (commaSep $ parseTerm PrecLam)
404 <|> mkRecord <$> braces (commaSep $ (,) <$> lowerCase <* colon <*> parseTerm PrecLam) 401 <|> mkRecord <$> braces (commaSep $ (,) <$> lowerCase <* colon <*> parseTerm PrecLam)
405 <|> do reserved "let" 402 <|> do reserved "let"
406 dcls <- localIndentation Ge $ localAbsoluteIndentation $ parseDefs xSLabelEnd 403 dcls <- localIndentation Ge $ localAbsoluteIndentation $ parseDefs xSLabelEnd
407 mkLets True <$> dsInfo <*> pure dcls <* reserved "in" <*> parseTerm PrecLam 404 mkLets True <$> dsInfo <*> pure dcls <* reserved "in" <*> parseTerm PrecLam
408 where 405 where
409 mkLeftSection (op, e) = SLam Visible (Wildcard SType) $ SGlobal op `SAppV` SVar (mempty, ".ls") 0 `SAppV` up1 e
410 mkRightSection (e, op) = SLam Visible (Wildcard SType) $ SGlobal op `SAppV` up1 e `SAppV` SVar (mempty, ".rs") 0
411
412 mkSwizzling term = swizzcall 406 mkSwizzling term = swizzcall
413 where 407 where
414 sc c = SBuiltin ['S',c] 408 sc c = SBuiltin ['S',c]
@@ -439,7 +433,12 @@ parseTerm prec = withRange setSI $ case prec of
439 mkValues = foldr (\x xs -> SBuiltin "Tuple2" `SAppV` x `SAppV` xs) 433 mkValues = foldr (\x xs -> SBuiltin "Tuple2" `SAppV` x `SAppV` xs)
440 (SBuiltin "Tuple0") 434 (SBuiltin "Tuple0")
441 435
436 mkLeftSection op e = SLam Visible (Wildcard SType) $ SGlobal op `SAppV` SVar (mempty, ".ls") 0 `SAppV` up1 e
437 mkRightSection e op = SLam Visible (Wildcard SType) $ SGlobal op `SAppV` up1 e `SAppV` SVar (mempty, ".rs") 0
438
442 mkTuple _ [x] = x 439 mkTuple _ [x] = x
440 mkTuple _ [LeftSection op x] = mkLeftSection op x
441 mkTuple _ [RightSection x op] = mkRightSection x op
443 mkTuple (Namespace level _) xs = foldl SAppV (SBuiltin (tuple ++ show (length xs))) xs 442 mkTuple (Namespace level _) xs = foldl SAppV (SBuiltin (tuple ++ show (length xs))) xs
444 where tuple = case level of 443 where tuple = case level of
445 Just TypeLevel -> "'Tuple" 444 Just TypeLevel -> "'Tuple"
@@ -460,7 +459,22 @@ parseTerm prec = withRange setSI $ case prec of
460 459
461 mkDotDot e f = SBuiltin "fromTo" `SAppV` e `SAppV` f 460 mkDotDot e f = SBuiltin "fromTo" `SAppV` e `SAppV` f
462 461
463 calculatePrecs dcls (e, xs) = calcPrec (\op x y -> SGlobal op `SAppV` x `SAppV` y) (getFixity dcls . snd) e xs 462 calculatePrecs :: Namespace -> DesugarInfo -> [Either SIName SExp] -> P SExp
463 calculatePrecs ns dcls = either fail return . f where
464 f (Left op@(_, "-"): xs) = calcPrec' (mkNat ns 0) <$> h op xs
465 f (Left op: xs) = h op xs <&> \((op, e): oe) -> LeftSection op $ calcPrec' e oe
466 f (Right t: xs) = either (\(op, xs) -> RightSection (calcPrec' t xs) op) (calcPrec' t) <$> cont (Right []) g xs
467 f [] = Left "TODO: better error message @461"
468 g op (Right t: xs) = (second ((op, t):) +++ ((op, t):)) <$> cont (Right []) g xs
469 g op [] = return $ Left (op, [])
470 g op _ = Left "TODO: better error message @470"
471 h op (Right t: xs) = ((op, t):) <$> cont [] h xs
472 h op _ = Left "TODO: better error message @472"
473 cont :: forall a . a -> (SIName -> [Either SIName SExp] -> Either String a) -> [Either SIName SExp] -> Either String a
474 cont _ f (Left op: xs) = f op xs
475 cont e _ [] = return e
476
477 calcPrec' = calcPrec (\op x y -> SGlobal op `SAppV` x `SAppV` y) (getFixity dcls . snd)
464 478
465 listCompr ge = foldr ($) 479 listCompr ge = foldr ($)
466 <$> try "List comprehension" ((SBuiltin "singleton" `SAppV`) <$ reservedOp "[" <*> parseTerm PrecLam <* reservedOp "|") 480 <$> try "List comprehension" ((SBuiltin "singleton" `SAppV`) <$ reservedOp "[" <*> parseTerm PrecLam <* reservedOp "|")
diff --git a/testdata/language-features/basic-list/list05.reject.out b/testdata/language-features/basic-list/list05.reject.out
index bfdc76b1..7633bb70 100644
--- a/testdata/language-features/basic-list/list05.reject.out
+++ b/testdata/language-features/basic-list/list05.reject.out
@@ -1,3 +1,3 @@
1"testdata/language-features/basic-list/list05.reject.lc" (line 2, column 1): 1"testdata/language-features/basic-list/list05.reject.lc" (line 2, column 1):
2unexpected end of input 2unexpected end of input
3expecting "if", "forall", "\\", "case", "|", "-", char literal, literal string, float literal, "#", natural, "_", "'", identifier, uppercase ident, dotdot expression, List comprehension, "[", left section, right section, "(", "{" or "let" \ No newline at end of file 3expecting "if", "forall", "\\", "case", "|", char literal, literal string, float literal, "#", natural, "_", "'", identifier, uppercase ident, dotdot expression, List comprehension, "[", "(", "{", "let", symbols, ":" or backquoted ident \ No newline at end of file
diff --git a/testdata/language-features/basic-list/list06.reject.out b/testdata/language-features/basic-list/list06.reject.out
index a4dec140..6bdb5d8a 100644
--- a/testdata/language-features/basic-list/list06.reject.out
+++ b/testdata/language-features/basic-list/list06.reject.out
@@ -1,3 +1,3 @@
1"testdata/language-features/basic-list/list06.reject.lc" (line 1, column 10): 1"testdata/language-features/basic-list/list06.reject.lc" (line 1, column 10):
2unexpected "," 2unexpected ","
3expecting "if", "forall", "\\", "case", "|", "-", char literal, literal string, float literal, "#", natural, "_", "'", identifier, uppercase ident, dotdot expression, List comprehension, "[", left section, right section, "(", "{", "let" or "]" \ No newline at end of file 3expecting "if", "forall", "\\", "case", "|", char literal, literal string, float literal, "#", natural, "_", "'", identifier, uppercase ident, dotdot expression, List comprehension, "[", "(", "{", "let", symbols, ":", backquoted ident or "]" \ No newline at end of file
diff --git a/testdata/language-features/basic-values/def05.reject.out b/testdata/language-features/basic-values/def05.reject.out
index 6efc8520..60095f3d 100644
--- a/testdata/language-features/basic-values/def05.reject.out
+++ b/testdata/language-features/basic-values/def05.reject.out
@@ -1,4 +1,4 @@
1"testdata/language-features/basic-values/def05.reject.lc" (line 4, column 1): 1"testdata/language-features/basic-values/def05.reject.lc" (line 4, column 1):
2unexpected end of input 2unexpected end of input
3expecting projection, swizzling, "@", char literal, literal string, float literal, "#", natural, "_", "'", identifier, uppercase ident, dotdot expression, List comprehension, "[", left section, right section, "(", "{", "let", symbols, ":", backquoted ident, "::", "~", "->", "=>", "where", "data", "class", "instance", type family, type instance, "type", typed ident, "infix", "infixl", "infixr", operator definition, lhs or pattern 3expecting projection, swizzling, "@", char literal, literal string, float literal, "#", natural, "_", "'", identifier, uppercase ident, dotdot expression, List comprehension, "[", "(", "{", "let", symbols, ":", backquoted ident, "::", "~", "->", "=>", "where", "data", "class", "instance", type family, type instance, "type", typed ident, "infix", "infixl", "infixr", operator definition, lhs or pattern
4different number of arguments of fun at testdata/language-features/basic-values/def05.reject.lc 1:1-1:4 \ No newline at end of file 4different number of arguments of fun at testdata/language-features/basic-values/def05.reject.lc 1:1-1:4 \ No newline at end of file
diff --git a/testdata/language-features/basic-values/def06.reject.out b/testdata/language-features/basic-values/def06.reject.out
index 92ab40a5..a4fac531 100644
--- a/testdata/language-features/basic-values/def06.reject.out
+++ b/testdata/language-features/basic-values/def06.reject.out
@@ -1,4 +1,4 @@
1"testdata/language-features/basic-values/def06.reject.lc" (line 5, column 1): 1"testdata/language-features/basic-values/def06.reject.lc" (line 5, column 1):
2unexpected end of input 2unexpected end of input
3expecting projection, swizzling, "@", char literal, literal string, float literal, "#", natural, "_", "'", identifier, uppercase ident, dotdot expression, List comprehension, "[", left section, right section, "(", "{", "let", symbols, ":", backquoted ident, "::", "~", "->", "=>", "where", "data", "class", "instance", type family, type instance, "type", typed ident, "infix", "infixl", "infixr", operator definition, lhs or pattern 3expecting projection, swizzling, "@", char literal, literal string, float literal, "#", natural, "_", "'", identifier, uppercase ident, dotdot expression, List comprehension, "[", "(", "{", "let", symbols, ":", backquoted ident, "::", "~", "->", "=>", "where", "data", "class", "instance", type family, type instance, "type", typed ident, "infix", "infixl", "infixr", operator definition, lhs or pattern
4different number of arguments of fun2 at testdata/language-features/basic-values/def06.reject.lc 1:1-1:5 \ No newline at end of file 4different number of arguments of fun2 at testdata/language-features/basic-values/def06.reject.lc 1:1-1:5 \ No newline at end of file
diff --git a/testdata/language-features/basic-values/redefine03.reject.out b/testdata/language-features/basic-values/redefine03.reject.out
index d2c29e14..a4e20764 100644
--- a/testdata/language-features/basic-values/redefine03.reject.out
+++ b/testdata/language-features/basic-values/redefine03.reject.out
@@ -1,4 +1,4 @@
1"testdata/language-features/basic-values/redefine03.reject.lc" (line 4, column 1): 1"testdata/language-features/basic-values/redefine03.reject.lc" (line 4, column 1):
2unexpected end of input 2unexpected end of input
3expecting projection, swizzling, "@", char literal, literal string, float literal, "#", natural, "_", "'", identifier, uppercase ident, dotdot expression, List comprehension, "[", left section, right section, "(", "{", "let", symbols, ":", backquoted ident, "::", "~", "->", "=>", "where", "data", "class", "instance", type family, type instance, "type", typed ident, "infix", "infixl", "infixr", operator definition, lhs or pattern 3expecting projection, swizzling, "@", char literal, literal string, float literal, "#", natural, "_", "'", identifier, uppercase ident, dotdot expression, List comprehension, "[", "(", "{", "let", symbols, ":", backquoted ident, "::", "~", "->", "=>", "where", "data", "class", "instance", type family, type instance, "type", typed ident, "infix", "infixl", "infixr", operator definition, lhs or pattern
4redefined x at testdata/language-features/basic-values/redefine03.reject.lc 2:9-2:10 \ No newline at end of file 4redefined x at testdata/language-features/basic-values/redefine03.reject.lc 2:9-2:10 \ No newline at end of file
diff --git a/testdata/listcompr01.reject.out b/testdata/listcompr01.reject.out
index d221be57..5cb55a0d 100644
--- a/testdata/listcompr01.reject.out
+++ b/testdata/listcompr01.reject.out
@@ -1,3 +1,3 @@
1"testdata/listcompr01.reject.lc" (line 6, column 42): 1"testdata/listcompr01.reject.lc" (line 6, column 42):
2unexpected ',' 2unexpected ','
3expecting end of "]", projection, swizzling, "@", char literal, literal string, float literal, "#", natural, "_", "'", identifier, uppercase ident, dotdot expression, List comprehension, "[", left section, right section, "(", "{", "let", symbols, ":", backquoted ident, "::", "~", "->", "=>", "where", "data", "class", "instance", type family, type instance, "type", typed ident, "infix", "infixl", "infixr", operator definition, lhs, pattern or end of input \ No newline at end of file 3expecting end of "]", projection, swizzling, "@", char literal, literal string, float literal, "#", natural, "_", "'", identifier, uppercase ident, dotdot expression, List comprehension, "[", "(", "{", "let", symbols, ":", backquoted ident, "::", "~", "->", "=>", "where", "data", "class", "instance", type family, type instance, "type", typed ident, "infix", "infixl", "infixr", operator definition, lhs, pattern or end of input \ No newline at end of file