@@ -1103,6 +1103,7 @@ WhereOrTerminator ::= WhereBlock | Terminator;
1104clause :: SyntaxInfo -> IdrisParser PClause
1104clause :: SyntaxInfo -> IdrisParser PClause
1105clause syn
1105clause syn
1106+ -- unnamed with or function clause (inside a with)
1106 = appExtent (do
1107 = appExtent (do
1107 wargs <- P.try (do pushIndent; some (wExpr syn))
1108 wargs <- P.try (do pushIndent; some (wExpr syn))
1108 ist <- get
1109 ist <- get
@@ -1123,6 +1124,7 @@ clause syn
1123 let withs = concat ds
1124 let withs = concat ds
1124 closeBlock
1125 closeBlock
1125 return $ \fc -> PWithR fc wargs wval pn withs))
1126 return $ \fc -> PWithR fc wargs wval pn withs))
1126 <|> do ty <- P.try (do pushIndent
1128 <|> do ty <- P.try (do pushIndent
1127 ty <- simpleExpr syn
1129 ty <- simpleExpr syn
1128 symbol "<=="
1130 symbol "<=="
@@ -1139,23 +1141,14 @@ clause syn
1139 ist <- get
1141 ist <- get
1140 put (ist { lastParse = Just n })
1142 put (ist { lastParse = Just n })
1141 return $ PClause fc n capp [] r wheres
1143 return $ PClause fc n capp [] r wheres
1142− <|> do (l, op, nfc) <- P.try (do
1144+ -- lhs application "with" clause or function clause
1143− pushIndent
1145+ <|> do pushIndent
1144− l <- argExpr syn
1146+ (n, nfc, capp, wargs) <- lhs
1145− (op, nfc) <- withExtent symbolicOperator
1147+ modify $ \ist -> ist { lastParse = Just n }
1146− when (op == "=" || op == "?=" ) $
1147− fail "infix clause definition with \"=\" and \"?=\" not supported "
1148− return (l, op, nfc))
1149− let n = expandNS syn (sUN op)
1151− wargs <- many (wExpr syn)
1152 (do (rs, fc) <- withExtent (rhs syn n)
1148 (do (rs, fc) <- withExtent (rhs syn n)
1153 let wsyn = syn { syn_namespace = [] }
1149 let wsyn = syn { syn_namespace = [] }
1154 (wheres, nmap) <- whereBlock n wsyn <* popIndent
1150 (wheres, nmap) <- whereBlock n wsyn <* popIndent
1155 <|> ([], []) <$ terminator
1151 <|> ([], []) <$ terminator
1157− let capp = PApp fc (PRef nfc [nfc] n) [pexp l, pexp r]
1158− put (ist { lastParse = Just n })
1159 return $ PClause fc n capp wargs rs wheres) <|> (do
1152 return $ PClause fc n capp wargs rs wheres) <|> (do
1160 popIndent
1153 popIndent
1161 ((wval, pn), fc) <- withExtent $ do
1154 ((wval, pn), fc) <- withExtent $ do
@@ -1166,41 +1159,33 @@ clause syn
1166 openBlock
1159 openBlock
1167 ds <- some $ fnDecl syn
1160 ds <- some $ fnDecl syn
1168 closeBlock
1161 closeBlock
1170− let capp = PApp fc (PRef fc [] n) [pexp l, pexp r]
1171− let withs = map (fillLHSD n capp wargs) $ concat ds
1172− put (ist { lastParse = Just n })
1173− return $ PWith fc n capp wargs wval pn withs)
1175− (n_in, nfc) <- withExtent fnName; let n = expandNS syn n_in
1176− args <- many (P.try (implicitArg (syn { inPattern = True } ))
1177− <|> P.try (constraintArg (syn { inPattern = True }))
1178− <|> (fmap pexp (argExpr syn)))
1179− wargs <- many (wExpr syn)
1180− (do (r, fc) <- withExtent (rhs syn n)
1181− let capp = PApp fc (PRef nfc [nfc] n) args
1182− let wsyn = syn { syn_namespace = [] }
1183− (wheres, nmap) <- whereBlock n wsyn <* popIndent
1184− <|> ([], []) <$ terminator
1186− put (ist { lastParse = Just n })
1187− return $ PClause fc n capp wargs r wheres) <|> (do
1190− put (ist { lastParse = Just n })
1191− ((wval, pn), fc) <- withExtent $ do
1192− wval <- bracketed syn
1196− ds <- some $ fnDecl syn
1199− let capp = PApp fc (PRef nfc [nfc] n) args
1200 let withs = map (fillLHSD n capp wargs) $ concat ds
1162 let withs = map (fillLHSD n capp wargs) $ concat ds
1201 return $ PWith fc n capp wargs wval pn withs)
1163 return $ PWith fc n capp wargs wval pn withs)
1202 <?> "function clause"
1164 <?> "function clause"
1166+ lhsInfixApp :: IdrisParser (Name, FC, [PArg], [PTerm])
1167+ lhsInfixApp = do l <- argExpr syn
1168+ (op, nfc) <- withExtent symbolicOperator
1169+ when (op == "=" || op == "?=" ) $
1170+ fail "infix clause definition with \"=\" and \"?=\" not supported "
1171+ let n = expandNS syn (sUN op)
1173+ wargs <- many (wExpr syn)
1174+ return (n, nfc, [pexp l, pexp r], wargs)
1176+ lhsPrefixApp :: IdrisParser (Name, FC, [PArg], [PTerm])
1177+ lhsPrefixApp = do (n, nfc) <- withExtent (expandNS syn <$> fnName)
1178+ args <- many (P.try (implicitArg (syn { inPattern = True } ))
1179+ <|> P.try (constraintArg (syn { inPattern = True }))
1180+ <|> (fmap pexp (argExpr syn)))
1181+ wargs <- many (wExpr syn)
1182+ return (n, nfc, args, wargs)
1184+ lhs :: IdrisParser (Name, FC, PTerm, [PTerm])
1185+ lhs = do ((n, nfc, args, wargs), lhs_fc) <- withExtent (P.try lhsInfixApp <|> lhsPrefixApp)
1186+ let capp = PApp lhs_fc (PRef nfc [nfc] n) args
1187+ return (n, nfc, capp, wargs)
1204 optProof = P.option Nothing (do keyword "proof"
1189 optProof = P.option Nothing (do keyword "proof"
1205 n <- withExtent fnName
1190 n <- withExtent fnName
1206 return (Just n))
1191 return (Just n))