on master help sign in
Unify almost identical checkFixity' functions.
635fb40Björn Aili
src/Idris/Parser.hs+1−9
@@ -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 = checkDeclFixity $
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,14 +618,6 @@ 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
622− checkFixity' p = do decl <- p
623− case getName decl of
624− Nothing -> return decl
625− Just n -> do checkFixity n
626− return decl
627− getName (PTy _ _ _ _ _ n _ _) = Just n
628− getName _ = Nothing
629
621
630{-| Parses a series of function and accessbility options
622{-| Parses a series of function and accessbility options
631
623
src/Idris/Parser/Data.hs+3−11
@@ -198,7 +198,7 @@ SimpleConstructorList ::=
198 ;
198 ;
199-}
199-}
200data_ :: SyntaxInfo -> IdrisParser PDecl
200data_ :: SyntaxInfo -> IdrisParser PDecl
201−data_ syn = checkFixity' $
201+data_ syn = checkDeclFixity $
202 do (doc, argDocs, acc, dataOpts) <- try (do
202 do (doc, argDocs, acc, dataOpts) <- try (do
203 (doc, argDocs) <- option noDocs docComment
203 (doc, argDocs) <- option noDocs docComment
204 pushIndent
204 pushIndent
@@ -251,14 +251,6 @@ data_ syn = checkFixity' $
251 return d)
251 return d)
252 <?> "data type declaration"
252 <?> "data type declaration"
253 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
262 mkPApp :: FC -> PTerm -> [PTerm] -> PTerm
254 mkPApp :: FC -> PTerm -> [PTerm] -> PTerm
263 mkPApp fc t [] = t
255 mkPApp fc t [] = t
264 mkPApp fc t xs = PApp fc t (map pexp xs)
256 mkPApp fc t xs = PApp fc t (map pexp xs)
@@ -286,7 +278,7 @@ constructor syn
286 let doc' = annotCode (tryFullExpr syn ist) doc
278 let doc' = annotCode (tryFullExpr syn ist) doc
287 argDocs' = [ (n, annotCode (tryFullExpr syn ist) d)
279 argDocs' = [ (n, annotCode (tryFullExpr syn ist) d)
288 | (n, d) <- argDocs ]
280 | (n, d) <- argDocs ]
289− checkFixity cn
281+ checkNameFixity cn
290 return (doc', argDocs', cn, nfc, ty, fc, fs)
282 return (doc', argDocs', cn, nfc, ty, fc, fs)
291 <?> "constructor"
283 <?> "constructor"
292
284
@@ -303,7 +295,7 @@ simpleConstructor syn
303 fc <- getFC
295 fc <- getFC
304 args <- many (do notEndApp
296 args <- many (do notEndApp
305 simpleExpr syn)
297 simpleExpr syn)
306− checkFixity cn
298+ checkNameFixity cn
307 return (doc', [], cn, nfc, args, fc, [])
299 return (doc', [], cn, nfc, args, fc, [])
308 <?> "constructor"
300 <?> "constructor"
309
301
src/Idris/Parser/Ops.hs+21−10
@@ -161,16 +161,27 @@ fixity = do pushIndent
161 extractName :: FixDecl -> String
161 extractName :: FixDecl -> String
162 extractName (Fix _ n) = n
162 extractName (Fix _ n) = n
163
163
164+-- | Check that a declaration of an operator also has fixity declared
165+checkDeclFixity :: IdrisParser PDecl -> IdrisParser PDecl
166+checkDeclFixity p = do decl <- p
167+ case getDeclName decl of
168+ Nothing -> return decl
169+ Just n -> do checkNameFixity n
170+ return decl
171+ where getDeclName (PTy _ _ _ _ _ n _ _ ) = Just n
172+ getDeclName (PData _ _ _ _ _ (PDatadecl n _ _ _)) = Just n
173+ getDeclName _ = Nothing
174+
164−{- | Checks that an operator name also has a fixity declaration -}
175+-- | Checks that an operator name also has a fixity declaration
165−checkFixity :: Name -> IdrisParser ()
176+checkNameFixity :: Name -> IdrisParser ()
166−checkFixity n = do fOk <- fixityOk n
177+checkNameFixity n = do fOk <- fixityOk n
167− unless fOk . fail $
178+ unless fOk . fail $
168− "Missing fixity declaration for " ++ show n
179+ "Missing fixity declaration for " ++ show n
169− where fixityOk (NS n _) = fixityOk n
180+ where fixityOk (NS n' _) = fixityOk n'
170− fixityOk (UN n) | all (flip elem opChars) (str n) =
181+ fixityOk (UN n') | all (flip elem opChars) (str n') =
171− do fixities <- fmap idris_infixes get
182+ do fixities <- fmap idris_infixes get
172− return . elem (str n) . map (\ (Fix _ op) -> op) $ fixities
183+ return . elem (str n') . map (\ (Fix _ op) -> op) $ fixities
173− | otherwise = return True
184+ | otherwise = return True
174 fixityOk _ = return True
185 fixityOk _ = return True
175
186
176{- | Parses a fixity declaration type (i.e. infix or prefix, associtavity)
187{- | Parses a fixity declaration type (i.e. infix or prefix, associtavity)