@@ -36,11 +36,17 @@ import Debug.Trace
3636
3737-- | Allow implicit type declarations
3838allowImp :: SyntaxInfo -> SyntaxInfo
39−allowImp syn = syn { implicitAllowed = True }
39+allowImp syn = syn { implicitAllowed = True,
40+ constraintAllowed = False }
4041
4142-- | Disallow implicit type declarations
4243disallowImp :: SyntaxInfo -> SyntaxInfo
43−disallowImp syn = syn { implicitAllowed = False }
44+disallowImp syn = syn { implicitAllowed = False,
45+ constraintAllowed = False }
46+
47+-- | Allow scoped constraint arguments
48+allowConstr :: SyntaxInfo -> SyntaxInfo
49+allowConstr syn = syn { constraintAllowed = True }
4450
4551{-| Parses an expression as a whole
4652@
@@ -327,7 +333,7 @@ CaseOption ::=
327333@
328334-}
329335caseOption :: SyntaxInfo -> IdrisParser (PTerm, PTerm)
330−caseOption syn = do lhs <- expr (syn { inPattern = True })
336+caseOption syn = do lhs <- expr (disallowImp (syn { inPattern = True }))
331337 r <- impossible <|> symbol "=>" *> expr syn
332338 return (lhs, r)
333339 <?> "case option"
@@ -432,7 +438,7 @@ simpleExpr syn =
432438 <|> do lchar '_'; return Placeholder
433439 <?> "expression"
434440
435−{- |Parses an expression in braces
441+{- |Parses an expression in parentheses
436442@
437443Bracketed ::= '(' Bracketed'
438444@
@@ -477,8 +483,8 @@ bracketed' open syn =
477483 Just o -> return $ PLam fc0 (sMN 1000 "ARG") NoFC Placeholder
478484 (PApp fc0 (PRef fc0 [] (sUN o)) [pexp l,
479485 pexp (PRef fc0 [] (sMN 1000 "ARG"))]))
480− <|> do l <- expr syn
481− bracketedExpr syn open l
486+ <|> do l <- expr (allowConstr syn)
487+ bracketedExpr (allowConstr syn) open l
482488
483489
484490
@@ -891,7 +897,7 @@ TypeExpr ::= ConstraintList? Expr;
891897 -}
892898typeExpr :: SyntaxInfo -> IdrisParser PTerm
893899typeExpr syn = do cs <- if implicitAllowed syn then constraintList syn else return []
894− sc <- expr syn
900+ sc <- expr (allowConstr syn)
895901 return (bindList (PPi constraint) cs sc)
896902 <?> "type signature"
897903
@@ -916,13 +922,13 @@ LambdaTail ::=
916922-}
917923lambda :: SyntaxInfo -> IdrisParser PTerm
918924lambda syn = do lchar '\\' <?> "lambda expression"
919− ((do xt <- try $ tyOptDeclList syn
925+ ((do xt <- try $ tyOptDeclList (disallowImp syn)
920926 fc <- getFC
921927 sc <- lambdaTail
922928 return (bindList (PLam fc) xt sc))
923929 <|>
924930 (do ps <- sepBy (do fc <- getFC
925− e <- simpleExpr (syn { inPattern = True })
931+ e <- simpleExpr (disallowImp (syn { inPattern = True }))
926932 return (fc, e))
927933 (lchar ',')
928934 sc <- lambdaTail
@@ -1055,7 +1061,7 @@ bindsymbol opts st syn
10551061explicitPi opts st syn
10561062 = do xt <- try (lchar '(' *> typeDeclList syn <* lchar ')')
10571063 binder <- bindsymbol opts st syn
1058− sc <- expr syn
1064+ sc <- expr (allowConstr syn)
10591065 return (bindList (PPi binder) xt sc)
10601066
10611067autoImplicit opts st syn
@@ -1064,7 +1070,7 @@ autoImplicit opts st syn
10641070 xt <- typeDeclList syn
10651071 lchar '}'
10661072 symbol "->"
1067− sc <- expr syn
1073+ sc <- expr (allowConstr syn)
10681074 highlightP kw AnnKeyword
10691075 return (bindList (PPi
10701076 (TacImp [] Dynamic (PTactics [ProofSearch True True 100 Nothing [] []]))) xt sc)
@@ -1078,7 +1084,7 @@ defaultImplicit opts st syn = do
10781084 xt <- typeDeclList syn
10791085 lchar '}'
10801086 symbol "->"
1081− sc <- expr syn
1087+ sc <- expr (allowConstr syn)
10821088 highlightP kw AnnKeyword
10831089 return (bindList (PPi (TacImp [] Dynamic script)) xt sc)
10841090
@@ -1096,6 +1102,14 @@ normalImplicit opts st syn = do
10961102 return (bindList (PPi im) xt
10971103 (bindList (PPi cl) cs sc))
10981104
1105+constraintPi opts st syn =
1106+ do cs <- constraintList1 syn
1107+ sc <- expr 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))
1111+ cs sc)
1112+
10991113implicitPi opts st syn =
11001114 autoImplicit opts st syn
11011115 <|> defaultImplicit opts st syn
@@ -1114,7 +1128,10 @@ pi syn =
11141128 st <- static
11151129 explicitPi opts st syn
11161130 <|> try (do lchar '{'; implicitPi opts st syn)
1117− <|> unboundPi opts st syn
1131+ <|> if constraintAllowed syn
1132+ then try (constraintPi opts st syn)
1133+ <|> unboundPi opts st syn
1134+ else unboundPi opts st syn
11181135 <?> "dependent type signature"
11191136
11201137{- | Parses Possible Options for Pi Expressions