on master help sign in
Refactor clause parser
1b110b9Jason Felice
src/Idris/Parser.hs+15−12
@@ -1103,6 +1103,7 @@ WhereOrTerminator ::= WhereBlock | Terminator;
1103-}
1103-}
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))
1127+ -- <==
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,22 +1141,23 @@ 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+ -- infix with or function clause
1143− pushIndent
1145+ <|> do pushIndent
1146+ ((n, nfc, args, wargs), lhs_fc) <- P.try $ withExtent (do
1144− l <- argExpr syn
1147+ l <- argExpr syn
1145− (op, nfc) <- withExtent symbolicOperator
1148+ (op, nfc) <- withExtent symbolicOperator
1146− when (op == "=" || op == "?=" ) $
1149+ when (op == "=" || op == "?=" ) $
1147− fail "infix clause definition with \"=\" and \"?=\" not supported "
1150+ fail "infix clause definition with \"=\" and \"?=\" not supported "
1148− return (l, op, nfc))
1149− let n = expandNS syn (sUN op)
1151+ let n = expandNS syn (sUN op)
1150− r <- argExpr syn
1152+ r <- argExpr syn
1151− wargs <- many (wExpr syn)
1153+ wargs <- many (wExpr syn)
1154+ return (n, nfc, [pexp l, pexp r], wargs))
1155+ let capp = PApp lhs_fc (PRef nfc [nfc] n) args
1152 (do (rs, fc) <- withExtent (rhs syn n)
1156 (do (rs, fc) <- withExtent (rhs syn n)
1153 let wsyn = syn { syn_namespace = [] }
1157 let wsyn = syn { syn_namespace = [] }
1154 (wheres, nmap) <- whereBlock n wsyn <* popIndent
1158 (wheres, nmap) <- whereBlock n wsyn <* popIndent
1155 <|> ([], []) <$ terminator
1159 <|> ([], []) <$ terminator
1156 ist <- get
1160 ist <- get
1157− let capp = PApp fc (PRef nfc [nfc] n) [pexp l, pexp r]
1158 put (ist { lastParse = Just n })
1161 put (ist { lastParse = Just n })
1159 return $ PClause fc n capp wargs rs wheres) <|> (do
1162 return $ PClause fc n capp wargs rs wheres) <|> (do
1160 popIndent
1163 popIndent
@@ -1167,10 +1170,10 @@ clause syn
1167 ds <- some $ fnDecl syn
1170 ds <- some $ fnDecl syn
1168 closeBlock
1171 closeBlock
1169 ist <- get
1172 ist <- get
1170− let capp = PApp fc (PRef fc [] n) [pexp l, pexp r]
1171 let withs = map (fillLHSD n capp wargs) $ concat ds
1173 let withs = map (fillLHSD n capp wargs) $ concat ds
1172 put (ist { lastParse = Just n })
1174 put (ist { lastParse = Just n })
1173 return $ PWith fc n capp wargs wval pn withs)
1175 return $ PWith fc n capp wargs wval pn withs)
1176+ -- prefix with or function clause
1174 <|> do pushIndent
1177 <|> do pushIndent
1175 ((n, nfc, args, wargs), lhs_fc) <- withExtent $ do
1178 ((n, nfc, args, wargs), lhs_fc) <- withExtent $ do
1176 (n, nfc) <- withExtent (expandNS syn <$> fnName)
1179 (n, nfc) <- withExtent (expandNS syn <$> fnName)