From 4bde587ab4f93e39b7f3ccaf76029ba4ac34ee60 Mon Sep 17 00:00:00 2001 From: aarne Date: Fri, 24 Nov 2006 17:09:40 +0000 Subject: [PATCH] improved error reporting in .ebnf format parser --- src/GF/Data/Parsers.hs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/GF/Data/Parsers.hs b/src/GF/Data/Parsers.hs index d9920c3d2..f9bf02598 100644 --- a/src/GF/Data/Parsers.hs +++ b/src/GF/Data/Parsers.hs @@ -33,6 +33,7 @@ module GF.Data.Parsers (-- * Main types and functions import GF.Data.Operations import Data.Char +import Data.List infixr 2 |||, +|| @@ -51,10 +52,12 @@ type Parser a b = [a] -> [(b,[a])] parseResults :: Parser a b -> [a] -> [b] parseResults p s = [x | (x,r) <- p s, null r] -parseResultErr :: Parser a b -> [a] -> Err b +parseResultErr :: Show a => Parser a b -> [a] -> Err b parseResultErr p s = case parseResults p s of [x] -> return x - [] -> Bad "no parse" + [] -> case + maximumBy (\x y -> compare (length y) (length x)) (s:[r | (_,r) <- p s]) of + r -> Bad $ "\nno parse; reached" ++++ take 300 (show r) _ -> Bad "ambiguous" (...) :: Parser a b -> Parser a c -> Parser a (b,c)