on master help sign in
Fix #3275
a6f56ceBjörn Aili
src/Idris/Parser.hs+7−15
@@ -598,7 +598,7 @@ fnDecl syn = try (do notEndBlock
598@
598@
599-}
599-}
600fnDecl' :: SyntaxInfo -> IdrisParser PDecl
600fnDecl' :: SyntaxInfo -> IdrisParser PDecl
601−fnDecl' syn = checkFixity $
601+fnDecl' syn = checkFixity' $
602 do (doc, argDocs, fc, opts', n, nfc, acc) <- try (do
602 do (doc, argDocs, fc, opts', n, nfc, acc) <- try (do
603 pushIndent
603 pushIndent
604 (doc, argDocs) <- docstring syn
604 (doc, argDocs) <- docstring syn
@@ -618,22 +618,14 @@ fnDecl' syn = checkFixity $
618 <|> caf syn
618 <|> caf syn
619 <|> pattern syn
619 <|> pattern syn
620 <?> "function declaration"
620 <?> "function declaration"
621− where checkFixity :: IdrisParser PDecl -> IdrisParser PDecl
621+ where checkFixity' :: IdrisParser PDecl -> IdrisParser PDecl
622− checkFixity p = do decl <- p
622+ checkFixity' p = do decl <- p
623− case getName decl of
623+ case getName decl of
624− Nothing -> return decl
624+ Nothing -> return decl
625− Just n -> do fOk <- fixityOK n
625+ Just n -> do checkFixity n
626− unless fOk . fail $
627− "Missing fixity declaration for " ++ show n
628− return decl
626+ return decl
629 getName (PTy _ _ _ _ _ n _ _) = Just n
627 getName (PTy _ _ _ _ _ n _ _) = Just n
630 getName _ = Nothing
628 getName _ = Nothing
631− fixityOK (NS n _) = fixityOK n
632− fixityOK (UN n) | all (flip elem opChars) (str n) =
633− do fixities <- fmap idris_infixes get
634− return . elem (str n) . map (\ (Fix _ op) -> op) $ fixities
635− | otherwise = return True
636− fixityOK _ = return True
637
629
638{-| Parses a series of function and accessbility options
630{-| Parses a series of function and accessbility options
639
631
src/Idris/Parser/Data.hs+12−1
@@ -198,7 +198,8 @@ SimpleConstructorList ::=
198 ;
198 ;
199-}
199-}
200data_ :: SyntaxInfo -> IdrisParser PDecl
200data_ :: SyntaxInfo -> IdrisParser PDecl
201+data_ syn = checkFixity' $
201−data_ syn = do (doc, argDocs, acc, dataOpts) <- try (do
202+ do (doc, argDocs, acc, dataOpts) <- try (do
202 (doc, argDocs) <- option noDocs docComment
203 (doc, argDocs) <- option noDocs docComment
203 pushIndent
204 pushIndent
204 acc <- accessibility
205 acc <- accessibility
@@ -250,6 +251,14 @@ data_ syn = do (doc, argDocs, acc, dataOpts) <- try (do
250 return d)
251 return d)
251 <?> "data type declaration"
252 <?> "data type declaration"
252 where
253 where
254+ checkFixity' :: IdrisParser PDecl -> IdrisParser PDecl
255+ checkFixity' p = do decl <- p
256+ case getName decl of
257+ Nothing -> return decl
258+ Just n -> do checkFixity n
259+ return decl
260+ getName (PData _ _ _ _ _ (PDatadecl tyn _ _ _)) = Just tyn
261+ getName _ = Nothing
253 mkPApp :: FC -> PTerm -> [PTerm] -> PTerm
262 mkPApp :: FC -> PTerm -> [PTerm] -> PTerm
254 mkPApp fc t [] = t
263 mkPApp fc t [] = t
255 mkPApp fc t xs = PApp fc t (map pexp xs)
264 mkPApp fc t xs = PApp fc t (map pexp xs)
@@ -277,6 +286,7 @@ constructor syn
277 let doc' = annotCode (tryFullExpr syn ist) doc
286 let doc' = annotCode (tryFullExpr syn ist) doc
278 argDocs' = [ (n, annotCode (tryFullExpr syn ist) d)
287 argDocs' = [ (n, annotCode (tryFullExpr syn ist) d)
279 | (n, d) <- argDocs ]
288 | (n, d) <- argDocs ]
289+ checkFixity cn
280 return (doc', argDocs', cn, nfc, ty, fc, fs)
290 return (doc', argDocs', cn, nfc, ty, fc, fs)
281 <?> "constructor"
291 <?> "constructor"
282
292
@@ -293,6 +303,7 @@ simpleConstructor syn
293 fc <- getFC
303 fc <- getFC
294 args <- many (do notEndApp
304 args <- many (do notEndApp
295 simpleExpr syn)
305 simpleExpr syn)
306+ checkFixity cn
296 return (doc', [], cn, nfc, args, fc, [])
307 return (doc', [], cn, nfc, args, fc, [])
297 <?> "constructor"
308 <?> "constructor"
298
309
src/Idris/Parser/Ops.hs+12
@@ -161,6 +161,18 @@ fixity = do pushIndent
161 extractName :: FixDecl -> String
161 extractName :: FixDecl -> String
162 extractName (Fix _ n) = n
162 extractName (Fix _ n) = n
163
163
164+{- | Checks that an operator name also has a fixity declaration -}
165+checkFixity :: Name -> IdrisParser ()
166+checkFixity n = do fOk <- fixityOk n
167+ unless fOk . fail $
168+ "Missing fixity declaration for " ++ show n
169+ where fixityOk (NS n _) = fixityOk n
170+ fixityOk (UN n) | all (flip elem opChars) (str n) =
171+ do fixities <- fmap idris_infixes get
172+ return . elem (str n) . map (\ (Fix _ op) -> op) $ fixities
173+ | otherwise = return True
174+ fixityOk _ = return True
175+
164{- | Parses a fixity declaration type (i.e. infix or prefix, associtavity)
176{- | Parses a fixity declaration type (i.e. infix or prefix, associtavity)
165@
177@
166 FixityType ::=
178 FixityType ::=