on master help sign in
Better warnings for `class` and `instance`
12594b3Jason Felice
src/Idris/Parser.hs+13−2
@@ -878,10 +878,15 @@ interface_ syn = do (doc, argDocs, acc)
878 fundeps :: IdrisParser [(Name, FC)]
878 fundeps :: IdrisParser [(Name, FC)]
879 fundeps = do lchar '|'; P.sepBy (withExtent name) (lchar ',')
879 fundeps = do lchar '|'; P.sepBy (withExtent name) (lchar ',')
880
880
881+ classWarning :: String
882+ classWarning = "Use of a fragile keyword `class`. " ++
883+ "`class` is provided for those coming from Haskell. " ++
884+ "Please use `interface` instead, which is equivalent."
885+
881 interfaceKeyword :: IdrisParser ()
886 interfaceKeyword :: IdrisParser ()
882 interfaceKeyword = keyword "interface"
887 interfaceKeyword = keyword "interface"
883 <|> do fc <- extent $ keyword "class"
888 <|> do fc <- extent $ keyword "class"
884− parserWarning fc Nothing (Msg "The 'class' keyword exists to migrate from Haskell--use 'interface' instead.")
889+ parserWarning fc Nothing (Msg classWarning)
885
890
886 carg :: IdrisParser (Name, FC, PTerm)
891 carg :: IdrisParser (Name, FC, PTerm)
887 carg = do lchar '('; (i, ifc) <- withExtent name; lchar ':'; ty <- expr syn; lchar ')'
892 carg = do lchar '('; (i, ifc) <- withExtent name; lchar ':'; ty <- expr syn; lchar ')'
@@ -926,10 +931,16 @@ implementation syn = do (doc, argDocs) <- docstring syn
926 let n = expandNS syn n_in
931 let n = expandNS syn n_in
927 return n
932 return n
928 <?> "implementation name"
933 <?> "implementation name"
934+
935+ instanceWarning :: String
936+ instanceWarning = "Use of fragile keyword `instance`. " ++
937+ "`instance` is provided for those coming from Haskell. " ++
938+ "Please use `implementation` (which is equivalent) instead, or omit it."
939+
929 implementationKeyword :: IdrisParser ()
940 implementationKeyword :: IdrisParser ()
930 implementationKeyword = keyword "implementation"
941 implementationKeyword = keyword "implementation"
931 <|> do fc <- extent $ keyword "instance"
942 <|> do fc <- extent $ keyword "instance"
932− parserWarning fc Nothing (Msg "The 'instance' keyword exists to migrate from Haskell--use 'implementation' (or omit it) instead.")
943+ parserWarning fc Nothing (Msg instanceWarning)
933
944
934 implementationUsing :: IdrisParser [Name]
945 implementationUsing :: IdrisParser [Name]
935 implementationUsing = do keyword "using"
946 implementationUsing = do keyword "using"