errorful parser

small
This commit is contained in:
crumbtoo
2024-01-22 09:59:48 -07:00
parent 5a659d22dd
commit c146e1c450
3 changed files with 10 additions and 5 deletions

View File

@@ -26,6 +26,7 @@ data MsgEnvelope e = MsgEnvelope
, _msgDiagnostic :: e , _msgDiagnostic :: e
, _msgSeverity :: Severity , _msgSeverity :: Severity
} }
deriving Functor
newtype RlpcError = Text [Text] newtype RlpcError = Text [Text]
deriving Show deriving Show
@@ -55,3 +56,6 @@ liftRlpcErrors :: (Functor m, IsRlpcError e)
-> ErrorfulT RlpcError m a -> ErrorfulT RlpcError m a
liftRlpcErrors = mapErrorful liftRlpcError liftRlpcErrors = mapErrorful liftRlpcError
instance (IsRlpcError e) => IsRlpcError (MsgEnvelope e) where
liftRlpcError msg = msg ^. msgDiagnostic & liftRlpcError

View File

@@ -161,7 +161,7 @@ mkProgram ds = do
pure $ RlpProgram (associate pt <$> ds) pure $ RlpProgram (associate pt <$> ds)
parseError :: Located RlpToken -> P a parseError :: Located RlpToken -> P a
parseError (Located ((l,c),s) t) = addFatal RlpParErrUnknown parseError (Located ((l,c),s) t) = addFatal RlpParErrUnexpectedToken
mkInfixD :: Assoc -> Int -> Name -> P PartialDecl' mkInfixD :: Assoc -> Int -> Name -> P PartialDecl'
mkInfixD a p n = do mkInfixD a p n = do

View File

@@ -37,6 +37,7 @@ import Core.Syntax (Name)
import Control.Monad import Control.Monad
import Control.Monad.State.Strict import Control.Monad.State.Strict
import Control.Monad.Errorful import Control.Monad.Errorful
import Compiler.RlpcError
import Data.Text (Text) import Data.Text (Text)
import Data.Maybe import Data.Maybe
import Data.Fix import Data.Fix
@@ -151,8 +152,10 @@ type OpInfo = (Assoc, Int)
data RlpParseError = RlpParErrOutOfBoundsPrecedence Int data RlpParseError = RlpParErrOutOfBoundsPrecedence Int
| RlpParErrDuplicateInfixD | RlpParErrDuplicateInfixD
| RlpParErrLexical | RlpParErrLexical
| RlpParErrUnknown | RlpParErrUnexpectedToken
deriving (Eq, Ord, Show) deriving (Eq, Ord, Show)
instance IsRlpcError RlpParseError where
---------------------------------------------------------------------------------- ----------------------------------------------------------------------------------
@@ -201,5 +204,3 @@ type PartialExpr' = Fix Partial
makeLenses ''AlexInput makeLenses ''AlexInput
makeLenses ''ParseState makeLenses ''ParseState
--------------------------------------------------------------------------------