on master help sign in
Merge pull request #86 from raichoo/fixity

Fixity

commit38bb87448bc193268e511973038ba2ff2456e07a authorEdwin Brady <edwin.brady@gmail.com> dateMon 19 Nov 2012, 06:32 (14 years ago) parent758d56aff56693
2 files changed+22−7
src/Idris/Docs.hs+4−1 src/Idris/Parser.hs+18−6
src/Idris/Docs.hs+4−1
@@ -100,11 +100,14 @@ docFun n
100100 [args] -> zip argnames args
101101 _ -> []
102102 let infixes = idris_infixes i
103− let fixdecls = filter (\(Fix _ x) -> x `isSuffixOf` (show n)) infixes
103+ let fixdecls = filter (\(Fix _ x) -> x == funName n) infixes
104104 let f = case fixdecls of
105105 [] -> Nothing
106106 (Fix x _:_) -> Just x
107107
108108 return (Doc n docstr args (delab i ty) f)
109+ where funName :: Name -> String
110+ funName (UN n) = n
111+ funName (NS n _) = funName n
109112
110113
src/Idris/Parser.hs+18−6
@@ -490,12 +490,24 @@ pFixity = do pushIndent
490490 pTerminator
491491 let prec = fromInteger i
492492 istate <- getState
493− let fs = map (Fix (f prec)) ops
494− setState (istate {
495− idris_infixes = nub $ sort (fs ++ idris_infixes istate),
496− ibc_write = map IBCFix fs ++ ibc_write istate })
497− fc <- pfc
498− return (PFix fc (f prec) ops)
493+ let infixes = idris_infixes istate
494+ let fs = map (Fix (f prec)) ops
495+ let redecl = map (alreadyDeclared infixes) fs
496+ if False `notElem` map checkValidity redecl
497+ then do setState (istate { idris_infixes = nub $ sort (fs ++ infixes)
498+ , ibc_write = map IBCFix fs ++ ibc_write istate
499+ })
500+ fc <- pfc
501+ return (PFix fc (f prec) ops)
502+ else fail "Illegal redeclaration of fixity"
503+ where alreadyDeclared :: [FixDecl] -> FixDecl -> (FixDecl, [FixDecl])
504+ alreadyDeclared fs f = (f, filter ((extractName f ==) . extractName) fs)
505+
506+ checkValidity :: (FixDecl, [FixDecl]) -> Bool
507+ checkValidity (f, fs) = all (== f) fs
508+
509+ extractName :: FixDecl -> String
510+ extractName (Fix _ n) = n
499511
500512fixity :: IParser (Int -> Fixity)
501513fixity = try (do reserved "infixl"; return Infixl)