-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Unary ops & some initial error reworking. * Add unary negate to prelude * Prelude tidy
- Loading branch information
Showing
11 changed files
with
206 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{-| | ||
Module : Eucalypt.Reporting.Classes | ||
Description : Type classes to implement for error reporting | ||
Copyright : (c) Greg Hawkins, 2018 | ||
License : | ||
Maintainer : greg@curvelogic.co.uk | ||
Stability : experimental | ||
-} | ||
module Eucalypt.Reporting.Classes where | ||
|
||
import Eucalypt.Reporting.Location as L | ||
import Text.PrettyPrint as P | ||
|
||
class Reportable a where | ||
-- | Location in SourceCode | ||
code :: a -> Maybe L.SourceSpan | ||
-- | Formatted error report | ||
report :: a -> P.Doc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,40 @@ | ||
{-| | ||
Module : Eucalypt.Reporting.Report | ||
Description : Facilities for reporting errors | ||
Copyright : (c) Greg Hawkins, 2018 | ||
License : | ||
Maintainer : greg@curvelogic.co.uk | ||
Stability : experimental | ||
-} | ||
module Eucalypt.Reporting.Report where | ||
|
||
import System.IO (hPrint, stderr) | ||
import Eucalypt.Reporting.Error | ||
import Eucalypt.Reporting.Classes | ||
import System.Exit | ||
import System.IO | ||
import qualified Text.PrettyPrint as P | ||
import Control.Exception.Safe | ||
|
||
-- | Report any errors to stderr | ||
reportErrors :: Show a => [a] -> IO () | ||
reportErrors = mapM_ (hPrint stderr) | ||
|
||
|
||
|
||
-- | Report an error to the console | ||
reportToConsole :: Reportable a => a -> IO () | ||
reportToConsole e = hPutStr stderr $ P.render $ report e | ||
|
||
|
||
|
||
-- | Attempt an IO action, but report and abort in the case of a | ||
-- reportable error. | ||
tryOrReport :: IO a -> IO a | ||
tryOrReport action = do | ||
result <- tryJust eucalyptError action | ||
case result of | ||
Left e -> reportToConsole e >> exitFailure | ||
Right v -> return v | ||
where | ||
eucalyptError :: EucalyptError -> Maybe EucalyptError | ||
eucalyptError = Just |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,34 @@ | ||
{-| | ||
Module : Eucalypt.Syntax.Error | ||
Description : Syntax errors from source or input specs | ||
Copyright : (c) Greg Hawkins, 2018 | ||
License : | ||
Maintainer : greg@curvelogic.co.uk | ||
Stability : experimental | ||
-} | ||
module Eucalypt.Syntax.Error where | ||
|
||
import Control.Exception.Safe | ||
import Data.List.NonEmpty as NE | ||
import Data.Void | ||
import Eucalypt.Reporting.Classes | ||
import Eucalypt.Reporting.Location | ||
import qualified Text.Megaparsec as M | ||
import qualified Text.PrettyPrint as P | ||
|
||
newtype SyntaxError | ||
= MegaparsecError (M.ParseError (M.Token String) Void) | ||
deriving (Show, Eq, Typeable) | ||
|
||
instance Exception SyntaxError | ||
|
||
toSpan :: NonEmpty M.SourcePos -> SourceSpan | ||
toSpan positions = (h, h) | ||
where | ||
h = SourcePosition $ NE.head positions | ||
|
||
-- | Make SyntaxError 'Reportable' | ||
instance Reportable SyntaxError where | ||
code (MegaparsecError pe) = Just . toSpan . M.errorPos $ pe | ||
report (MegaparsecError pe) = P.text "SYNTAX ERROR" P.$$ P.text msg | ||
where msg = M.parseErrorPretty pe |
Oops, something went wrong.