Skip to content

Commit

Permalink
Add line numbers to unknown fields error message.
Browse files Browse the repository at this point in the history
  • Loading branch information
nominolo committed Jul 30, 2007
1 parent dc8e02b commit 5cb7e95
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Distribution/PackageDescription.hs
Expand Up @@ -1093,21 +1093,24 @@ parseFields descrs ini fields =
do (a, unknowns) <- foldM (parseField descrs) (ini, []) fields
when (not (null unknowns)) $ do
warning $ render $
text "Unknown fields:" <+> commaSep (reverse unknowns) $+$
text "Unknown fields:" <+>
commaSep (map (\(l,u) -> u ++ " (line " ++ show l ++ ")")
(reverse unknowns))
$+$
text "Fields allowed in this section:" $$
nest 4 (commaSep $ map fieldName descrs)
return a
where
commaSep = fsep . punctuate comma . map text

parseField :: [FieldDescr a] -> (a,[String]) -> Field -> ParseResult (a, [String])
parseField :: [FieldDescr a] -> (a,[(Int,String)]) -> Field -> ParseResult (a, [(Int,String)])
parseField ((FieldDescr name _ parse):fields) (a, us) (F line f val)
| name == f = parse line val a >>= \a' -> return (a',us)
| otherwise = parseField fields (a,us) (F line f val)
-- ignore "x-" extension fields without a warning
parseField [] (a,us) (F _ ('x':'-':_) _) = return (a, us)
parseField [] (a,us) (F _ f _) = do
return (a, f:us)
parseField [] (a,us) (F l f _) = do
return (a, ((l,f):us))
parseField _ _ _ = error "'parseField' called on a non-field. This is a bug."


Expand Down

0 comments on commit 5cb7e95

Please sign in to comment.