mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 19:42:50 -06:00
improved error reporting in .ebnf format parser
This commit is contained in:
@@ -33,6 +33,7 @@ module GF.Data.Parsers (-- * Main types and functions
|
|||||||
|
|
||||||
import GF.Data.Operations
|
import GF.Data.Operations
|
||||||
import Data.Char
|
import Data.Char
|
||||||
|
import Data.List
|
||||||
|
|
||||||
|
|
||||||
infixr 2 |||, +||
|
infixr 2 |||, +||
|
||||||
@@ -51,10 +52,12 @@ type Parser a b = [a] -> [(b,[a])]
|
|||||||
parseResults :: Parser a b -> [a] -> [b]
|
parseResults :: Parser a b -> [a] -> [b]
|
||||||
parseResults p s = [x | (x,r) <- p s, null r]
|
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
|
parseResultErr p s = case parseResults p s of
|
||||||
[x] -> return x
|
[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"
|
_ -> Bad "ambiguous"
|
||||||
|
|
||||||
(...) :: Parser a b -> Parser a c -> Parser a (b,c)
|
(...) :: Parser a b -> Parser a c -> Parser a (b,c)
|
||||||
|
|||||||
Reference in New Issue
Block a user