summaryrefslogtreecommitdiff
path: root/src/GF
diff options
context:
space:
mode:
authoraarne <aarne@cs.chalmers.se>2006-11-24 17:09:40 +0000
committeraarne <aarne@cs.chalmers.se>2006-11-24 17:09:40 +0000
commit13531a66a3cd2c65eeac8ce12b283528744a7adf (patch)
treeeb191eeb82d5791d334de70defdfcfb951627a1b /src/GF
parent35eaaa0da6f5d17e172674b7939310530d92ec2b (diff)
improved error reporting in .ebnf format parser
Diffstat (limited to 'src/GF')
-rw-r--r--src/GF/Data/Parsers.hs7
1 files 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)