1
Fork 0

simplify the error position code

This commit is contained in:
Jake Wheat 2013-12-13 20:08:43 +02:00
parent 182526d1fc
commit 99409fbc15

View file

@ -24,8 +24,8 @@
> -> Either ParseError QueryExpr > -> Either ParseError QueryExpr
> parseQueryExpr f p src = > parseQueryExpr f p src =
> either (Left . convParseError src) Right > either (Left . convParseError src) Right
> $ parse (setPos f p *> whiteSpace > $ parse (setPos p *> whiteSpace
> *> queryExpr <* eof) "" src > *> queryExpr <* eof) f src
> parseScalarExpr :: FilePath > parseScalarExpr :: FilePath
> -> Maybe (Int,Int) > -> Maybe (Int,Int)
@ -33,18 +33,17 @@
> -> Either ParseError ScalarExpr > -> Either ParseError ScalarExpr
> parseScalarExpr f p src = > parseScalarExpr f p src =
> either (Left . convParseError src) Right > either (Left . convParseError src) Right
> $ parse (setPos f p *> whiteSpace > $ parse (setPos p *> whiteSpace
> *> scalarExpr <* eof) "" src > *> scalarExpr <* eof) f src
> setPos :: FilePath -> Maybe (Int,Int) -> P () > setPos :: Maybe (Int,Int) -> P ()
> setPos f p = do > setPos Nothing = return ()
> sp <- getPosition > setPos (Just (l,c)) =
> let sp' = setSourceName sp f > getPosition
> sp'' = maybe sp' > >>= (return
> (\(l,c) -> flip setSourceColumn c > . flip setSourceColumn c
> $ setSourceLine sp' l) > . flip setSourceLine l)
> p > >>= setPosition
> setPosition sp''
> data ParseError = ParseError > data ParseError = ParseError
> {peErrorString :: String > {peErrorString :: String
@ -52,7 +51,6 @@
> ,pePosition :: (Int,Int) > ,pePosition :: (Int,Int)
> ,peFormattedError :: String > ,peFormattedError :: String
> } deriving (Eq,Show) > } deriving (Eq,Show)
> convParseError :: String -> P.ParseError -> ParseError > convParseError :: String -> P.ParseError -> ParseError
> convParseError src e = > convParseError src e =
> ParseError > ParseError