on master help sign in
Extract lhsPrefixApp, lhsInfixApp
0296c12Jason Felice
src/Idris/Parser.hs+19−18
@@ -1164,25 +1164,26 @@ clause syn
1164 return $ PWith fc n capp wargs wval pn withs)
1164 return $ PWith fc n capp wargs wval pn withs)
1165 <?> "function clause"
1165 <?> "function clause"
1166 where
1166 where
1167+ lhsInfixApp :: IdrisParser (Name, FC, [PArg], [PTerm])
1168+ lhsInfixApp = do l <- argExpr syn
1169+ (op, nfc) <- withExtent symbolicOperator
1170+ when (op == "=" || op == "?=" ) $
1171+ fail "infix clause definition with \"=\" and \"?=\" not supported "
1172+ let n = expandNS syn (sUN op)
1173+ r <- argExpr syn
1174+ wargs <- many (wExpr syn)
1175+ return (n, nfc, [pexp l, pexp r], wargs)
1176+
1177+ lhsPrefixApp :: IdrisParser (Name, FC, [PArg], [PTerm])
1178+ lhsPrefixApp = do (n, nfc) <- withExtent (expandNS syn <$> fnName)
1179+ args <- many (P.try (implicitArg (syn { inPattern = True } ))
1180+ <|> P.try (constraintArg (syn { inPattern = True }))
1181+ <|> (fmap pexp (argExpr syn)))
1182+ wargs <- many (wExpr syn)
1183+ return (n, nfc, args, wargs)
1184+
1167 lhs :: IdrisParser (Name, FC, PTerm, [PTerm])
1185 lhs :: IdrisParser (Name, FC, PTerm, [PTerm])
1168− lhs = do ((n, nfc, args, wargs), lhs_fc) <- P.try $ withExtent (do
1186+ lhs = do ((n, nfc, args, wargs), lhs_fc) <- withExtent (P.try lhsInfixApp <|> lhsPrefixApp)
1169− l <- argExpr syn
1170− (op, nfc) <- withExtent symbolicOperator
1171− when (op == "=" || op == "?=" ) $
1172− fail "infix clause definition with \"=\" and \"?=\" not supported "
1173− let n = expandNS syn (sUN op)
1174− r <- argExpr syn
1175− wargs <- many (wExpr syn)
1176− return (n, nfc, [pexp l, pexp r], wargs))
1177− let capp = PApp lhs_fc (PRef nfc [nfc] n) args
1178− return (n, nfc, capp, wargs)
1179− <|> do ((n, nfc, args, wargs), lhs_fc) <- withExtent $ do
1180− (n, nfc) <- withExtent (expandNS syn <$> fnName)
1181− args <- many (P.try (implicitArg (syn { inPattern = True } ))
1182− <|> P.try (constraintArg (syn { inPattern = True }))
1183− <|> (fmap pexp (argExpr syn)))
1184− wargs <- many (wExpr syn)
1185− return (n, nfc, args, wargs)
1186 let capp = PApp lhs_fc (PRef nfc [nfc] n) args
1187 let capp = PApp lhs_fc (PRef nfc [nfc] n) args
1187 return (n, nfc, capp, wargs)
1188 return (n, nfc, capp, wargs)
1188
1189