on master help sign in
Missing fixity declarations for infix operator functions is now a parser error.

Fixes #617.

commitd1663cc4f5d9ed37817fff81545ca1aa3cbf0e9e authorDavid Christiansen <david@davidchristiansen.dk> dateTue 19 Nov 2013, 11:48 (13 years ago) parent9449751
1 file changed+26−10
src/Idris/Parser.hs+26−10
src/Idris/Parser.hs+26−10
@@ -30,6 +30,7 @@ import Idris.ParseHelpers
3030import Idris.ParseOps
3131import Idris.ParseExpr
3232import Idris.ParseData
33+import Core.CoreParser (opChars)
3334
3435import Paths_idris
3536
@@ -245,13 +246,11 @@ syntaxSym = try (do lchar '['; n <- name; lchar ']'
245246 FunDecl ::= FunDecl';
246247-}
247248fnDecl :: SyntaxInfo -> IdrisParser [PDecl]
248−fnDecl syn
249− = try (do notEndBlock
250− d <- fnDecl' syn
251− i <- get
252− let d' = fmap (desugar syn i) d
253− return [d'])
254− <?> "function declaration"
249+fnDecl syn = try (do notEndBlock
250+ d <- fnDecl' syn
251+ i <- get
252+ let d' = fmap (desugar syn i) d
253+ return [d']) <?> "function declaration"
255254
256255{- Parses a function declaration
257256 FunDecl' ::=
@@ -262,7 +261,8 @@ fnDecl syn
262261 ;
263262-}
264263fnDecl' :: SyntaxInfo -> IdrisParser PDecl
265−fnDecl' syn = do (doc, fc, opts', n, acc) <- try (do
264+fnDecl' syn = checkFixity $
265+ do (doc, fc, opts', n, acc) <- try (do
266266 doc <- option "" (docComment '|')
267267 pushIndent
268268 ist <- get
@@ -285,7 +285,22 @@ fnDecl' syn = do (doc, fc, opts', n, acc) <- try (do
285285 <|> caf syn
286286 <|> pattern syn
287287 <?> "function declaration"
288−
288+ where checkFixity :: IdrisParser PDecl -> IdrisParser PDecl
289+ checkFixity p = do decl <- p
290+ case getName decl of
291+ Nothing -> return decl
292+ Just n -> do fOk <- fixityOK n
293+ unless fOk . fail $
294+ "Missing fixity declaration for " ++ show n
295+ return decl
296+ getName (PTy _ _ _ _ n _) = Just n
297+ getName _ = Nothing
298+ fixityOK (NS n _) = fixityOK n
299+ fixityOK (UN n) | all (flip elem opChars) n =
300+ do fixities <- fmap idris_infixes get
301+ return . elem n . map (\ (Fix _ op) -> op) $ fixities
302+ | otherwise = return True
303+ fixityOK _ = return True
289304
290305{- Parses function options given initial options
291306FnOpts ::= 'total'
@@ -649,7 +664,8 @@ clause syn
649664 pushIndent
650665 l <- argExpr syn
651666 op <- operator
652− when (op == "=" || op == "?=" ) (fail "infix clause definition with \"=\" and \"?=\" not supported ")
667+ when (op == "=" || op == "?=" ) $
668+ fail "infix clause definition with \"=\" and \"?=\" not supported "
653669 return (l, op))
654670 let n = expandNS syn (UN op)
655671 r <- argExpr syn