@@ -36,11 +36,17 @@ import Debug.Trace
37-- | Allow implicit type declarations
37-- | Allow implicit type declarations
38allowImp :: SyntaxInfo -> SyntaxInfo
38allowImp :: SyntaxInfo -> SyntaxInfo
39−allowImp syn = syn { implicitAllowed = True }
39+allowImp syn = syn { implicitAllowed = True,
40+ constraintAllowed = False }
41-- | Disallow implicit type declarations
42-- | Disallow implicit type declarations
42disallowImp :: SyntaxInfo -> SyntaxInfo
43disallowImp :: SyntaxInfo -> SyntaxInfo
43−disallowImp syn = syn { implicitAllowed = False }
44+disallowImp syn = syn { implicitAllowed = False,
45+ constraintAllowed = False }
47+-- | Allow scoped constraint arguments
48+allowConstr :: SyntaxInfo -> SyntaxInfo
49+allowConstr syn = syn { constraintAllowed = True }
45{-| Parses an expression as a whole
51{-| Parses an expression as a whole
@@ -327,7 +333,7 @@ CaseOption ::=
329caseOption :: SyntaxInfo -> IdrisParser (PTerm, PTerm)
335caseOption :: SyntaxInfo -> IdrisParser (PTerm, PTerm)
330−caseOption syn = do lhs <- expr (syn { inPattern = True })
336+caseOption syn = do lhs <- expr (disallowImp (syn { inPattern = True }))
331 r <- impossible <|> symbol "=>" *> expr syn
337 r <- impossible <|> symbol "=>" *> expr syn
332 return (lhs, r)
338 return (lhs, r)
333 <?> "case option"
339 <?> "case option"
@@ -432,7 +438,7 @@ simpleExpr syn =
432 <|> do lchar '_'; return Placeholder
438 <|> do lchar '_'; return Placeholder
433 <?> "expression"
439 <?> "expression"
435−{- |Parses an expression in braces
441+{- |Parses an expression in parentheses
437Bracketed ::= '(' Bracketed'
443Bracketed ::= '(' Bracketed'
@@ -477,8 +483,8 @@ bracketed' open syn =
477 Just o -> return $ PLam fc0 (sMN 1000 "ARG") NoFC Placeholder
483 Just o -> return $ PLam fc0 (sMN 1000 "ARG") NoFC Placeholder
478 (PApp fc0 (PRef fc0 [] (sUN o)) [pexp l,
484 (PApp fc0 (PRef fc0 [] (sUN o)) [pexp l,
479 pexp (PRef fc0 [] (sMN 1000 "ARG"))]))
485 pexp (PRef fc0 [] (sMN 1000 "ARG"))]))
480− <|> do l <- expr syn
486+ <|> do l <- expr (allowConstr syn)
481− bracketedExpr syn open l
487+ bracketedExpr (allowConstr syn) open l
@@ -891,7 +897,7 @@ TypeExpr ::= ConstraintList? Expr;
892typeExpr :: SyntaxInfo -> IdrisParser PTerm
898typeExpr :: SyntaxInfo -> IdrisParser PTerm
893typeExpr syn = do cs <- if implicitAllowed syn then constraintList syn else return []
899typeExpr syn = do cs <- if implicitAllowed syn then constraintList syn else return []
894− sc <- expr syn
900+ sc <- expr (allowConstr syn)
895 return (bindList (PPi constraint) cs sc)
901 return (bindList (PPi constraint) cs sc)
896 <?> "type signature"
902 <?> "type signature"
@@ -916,13 +922,13 @@ LambdaTail ::=
917lambda :: SyntaxInfo -> IdrisParser PTerm
923lambda :: SyntaxInfo -> IdrisParser PTerm
918lambda syn = do lchar '\\' <?> "lambda expression"
924lambda syn = do lchar '\\' <?> "lambda expression"
919− ((do xt <- try $ tyOptDeclList syn
925+ ((do xt <- try $ tyOptDeclList (disallowImp syn)
920 fc <- getFC
926 fc <- getFC
921 sc <- lambdaTail
927 sc <- lambdaTail
922 return (bindList (PLam fc) xt sc))
928 return (bindList (PLam fc) xt sc))
924 (do ps <- sepBy (do fc <- getFC
930 (do ps <- sepBy (do fc <- getFC
925− e <- simpleExpr (syn { inPattern = True })
931+ e <- simpleExpr (disallowImp (syn { inPattern = True }))
926 return (fc, e))
932 return (fc, e))
927 (lchar ',')
933 (lchar ',')
928 sc <- lambdaTail
934 sc <- lambdaTail
@@ -1055,7 +1061,7 @@ bindsymbol opts st syn
1055explicitPi opts st syn
1061explicitPi opts st syn
1056 = do xt <- try (lchar '(' *> typeDeclList syn <* lchar ')')
1062 = do xt <- try (lchar '(' *> typeDeclList syn <* lchar ')')
1057 binder <- bindsymbol opts st syn
1063 binder <- bindsymbol opts st syn
1058− sc <- expr syn
1064+ sc <- expr (allowConstr syn)
1059 return (bindList (PPi binder) xt sc)
1065 return (bindList (PPi binder) xt sc)
1061autoImplicit opts st syn
1067autoImplicit opts st syn
@@ -1064,7 +1070,7 @@ autoImplicit opts st syn
1064 xt <- typeDeclList syn
1070 xt <- typeDeclList syn
1065 lchar '}'
1071 lchar '}'
1066 symbol "->"
1072 symbol "->"
1067− sc <- expr syn
1073+ sc <- expr (allowConstr syn)
1068 highlightP kw AnnKeyword
1074 highlightP kw AnnKeyword
1069 return (bindList (PPi
1075 return (bindList (PPi
1070 (TacImp [] Dynamic (PTactics [ProofSearch True True 100 Nothing [] []]))) xt sc)
1076 (TacImp [] Dynamic (PTactics [ProofSearch True True 100 Nothing [] []]))) xt sc)
@@ -1078,7 +1084,7 @@ defaultImplicit opts st syn = do
1078 xt <- typeDeclList syn
1084 xt <- typeDeclList syn
1079 lchar '}'
1085 lchar '}'
1080 symbol "->"
1086 symbol "->"
1081− sc <- expr syn
1087+ sc <- expr (allowConstr syn)
1082 highlightP kw AnnKeyword
1088 highlightP kw AnnKeyword
1083 return (bindList (PPi (TacImp [] Dynamic script)) xt sc)
1089 return (bindList (PPi (TacImp [] Dynamic script)) xt sc)
@@ -1096,6 +1102,14 @@ normalImplicit opts st syn = do
1096 return (bindList (PPi im) xt
1102 return (bindList (PPi im) xt
1097 (bindList (PPi cl) cs sc))
1103 (bindList (PPi cl) cs sc))
1105+constraintPi opts st syn =
1106+ do cs <- constraintList1 syn
1108+ if implicitAllowed syn
1109+ then return (bindList (PPi constraint) cs sc)
1110+ else return (bindList (PPi (Imp opts st False (Just (Impl True False)) True))
1099implicitPi opts st syn =
1113implicitPi opts st syn =
1100 autoImplicit opts st syn
1114 autoImplicit opts st syn
1101 <|> defaultImplicit opts st syn
1115 <|> defaultImplicit opts st syn
@@ -1114,7 +1128,10 @@ pi syn =
1114 st <- static
1128 st <- static
1115 explicitPi opts st syn
1129 explicitPi opts st syn
1116 <|> try (do lchar '{'; implicitPi opts st syn)
1130 <|> try (do lchar '{'; implicitPi opts st syn)
1131+ <|> if constraintAllowed syn
1132+ then try (constraintPi opts st syn)
1117− <|> unboundPi opts st syn
1133+ <|> unboundPi opts st syn
1134+ else unboundPi opts st syn
1118 <?> "dependent type signature"
1135 <?> "dependent type signature"
1120{- | Parses Possible Options for Pi Expressions
1137{- | Parses Possible Options for Pi Expressions