lib: remove old code for include file parse errors
This commit is contained in:
parent
31d4e930e7
commit
26369c28a3
@ -12,7 +12,6 @@ module Text.Megaparsec.Custom (
|
|||||||
-- * Constructing custom parse errors
|
-- * Constructing custom parse errors
|
||||||
parseErrorAt,
|
parseErrorAt,
|
||||||
parseErrorAtRegion,
|
parseErrorAtRegion,
|
||||||
withSource,
|
|
||||||
|
|
||||||
-- * Pretty-printing custom parse errors
|
-- * Pretty-printing custom parse errors
|
||||||
customParseErrorPretty,
|
customParseErrorPretty,
|
||||||
@ -64,10 +63,6 @@ data CustomErr
|
|||||||
= ErrorFailAt SourcePos -- Starting position
|
= ErrorFailAt SourcePos -- Starting position
|
||||||
Pos -- Ending position (column; same line as start)
|
Pos -- Ending position (column; same line as start)
|
||||||
String -- Error message
|
String -- Error message
|
||||||
-- | Attach a source file to a parse error (for error reporting from
|
|
||||||
-- include files, e.g. with the 'region' parser combinator)
|
|
||||||
| ErrorWithSource Text -- Source file contents
|
|
||||||
(ParseError Char CustomErr) -- The original
|
|
||||||
deriving (Show, Eq, Ord)
|
deriving (Show, Eq, Ord)
|
||||||
|
|
||||||
-- We require an 'Ord' instance for 'CustomError' so that they may be
|
-- We require an 'Ord' instance for 'CustomError' so that they may be
|
||||||
@ -79,7 +74,6 @@ deriving instance (Ord c, Ord e) => Ord (ParseError c e)
|
|||||||
|
|
||||||
instance ShowErrorComponent CustomErr where
|
instance ShowErrorComponent CustomErr where
|
||||||
showErrorComponent (ErrorFailAt _ _ errMsg) = errMsg
|
showErrorComponent (ErrorFailAt _ _ errMsg) = errMsg
|
||||||
showErrorComponent (ErrorWithSource _ e) = parseErrorTextPretty e
|
|
||||||
|
|
||||||
|
|
||||||
--- * Constructing custom parse errors
|
--- * Constructing custom parse errors
|
||||||
@ -107,13 +101,6 @@ parseErrorAtRegion startPos endPos msg =
|
|||||||
then endCol' else startCol
|
then endCol' else startCol
|
||||||
in ErrorFailAt startPos endCol msg
|
in ErrorFailAt startPos endCol msg
|
||||||
|
|
||||||
-- | Attach a source file to a parse error. Intended for use with the
|
|
||||||
-- 'region' parser combinator.
|
|
||||||
|
|
||||||
withSource :: Text -> ParseError Char CustomErr -> ParseError Char CustomErr
|
|
||||||
withSource s e =
|
|
||||||
FancyError (errorPos e) $ S.singleton $ ErrorCustom $ ErrorWithSource s e
|
|
||||||
|
|
||||||
|
|
||||||
--- * Pretty-printing custom parse errors
|
--- * Pretty-printing custom parse errors
|
||||||
|
|
||||||
@ -127,9 +114,6 @@ customParseErrorPretty :: Text -> ParseError Char CustomErr -> String
|
|||||||
customParseErrorPretty source err = case findCustomError err of
|
customParseErrorPretty source err = case findCustomError err of
|
||||||
Nothing -> customParseErrorPretty' source err pos1
|
Nothing -> customParseErrorPretty' source err pos1
|
||||||
|
|
||||||
Just (ErrorWithSource customSource customErr) ->
|
|
||||||
customParseErrorPretty customSource customErr
|
|
||||||
|
|
||||||
Just (ErrorFailAt sourcePos col errMsg) ->
|
Just (ErrorFailAt sourcePos col errMsg) ->
|
||||||
let newPositionStack = sourcePos NE.:| NE.tail (errorPos err)
|
let newPositionStack = sourcePos NE.:| NE.tail (errorPos err)
|
||||||
errorIntervalLength = mkPos $ max 1 $
|
errorIntervalLength = mkPos $ max 1 $
|
||||||
@ -200,6 +184,7 @@ data FinalParseErrorBundle' e = FinalParseErrorBundle'
|
|||||||
|
|
||||||
type FinalParseErrorBundle = FinalParseErrorBundle' CustomErr
|
type FinalParseErrorBundle = FinalParseErrorBundle' CustomErr
|
||||||
|
|
||||||
|
|
||||||
--- * Constructing and throwing final parse errors
|
--- * Constructing and throwing final parse errors
|
||||||
|
|
||||||
-- | Convert a "regular" parse error into a "final" parse error.
|
-- | Convert a "regular" parse error into a "final" parse error.
|
||||||
@ -229,6 +214,7 @@ finalCustomFailure
|
|||||||
:: (MonadParsec e s m, MonadError (FinalParseError' e) m) => e -> m a
|
:: (MonadParsec e s m, MonadError (FinalParseError' e) m) => e -> m a
|
||||||
finalCustomFailure = finalFancyFailure . S.singleton . ErrorCustom
|
finalCustomFailure = finalFancyFailure . S.singleton . ErrorCustom
|
||||||
|
|
||||||
|
|
||||||
--- * Handling errors from include files with "final" parse errors
|
--- * Handling errors from include files with "final" parse errors
|
||||||
|
|
||||||
-- Some care must be taken for sources to be attached to the right parse
|
-- Some care must be taken for sources to be attached to the right parse
|
||||||
@ -268,6 +254,7 @@ attachSource filePath sourceText finalParseError =
|
|||||||
{ sourceFileStack = filePath NE.<| sourceFileStack bundle
|
{ sourceFileStack = filePath NE.<| sourceFileStack bundle
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
--- * Pretty-printing final parse errors
|
--- * Pretty-printing final parse errors
|
||||||
|
|
||||||
-- | Pretty-print a "final" parse error: print the stack of include files,
|
-- | Pretty-print a "final" parse error: print the stack of include files,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user