RlpcError

This commit is contained in:
crumbtoo
2023-12-28 15:55:24 -07:00
parent c2960e4acc
commit 526bf0734e
7 changed files with 58 additions and 4 deletions

View File

@@ -6,6 +6,7 @@ Description : Lexical analysis for the core language
{-# LANGUAGE OverloadedStrings #-}
module Core.Lex
( lexCore
, lexCoreR
, lexCore'
, CoreToken(..)
, SrcError(..)
@@ -21,6 +22,7 @@ import Data.Text qualified as T
import Data.String (IsString(..))
import Core.Syntax
import Compiler.RLPC
import Compiler.RlpcError
import Lens.Micro
import Lens.Micro.TH
}
@@ -177,6 +179,9 @@ lexCore s = case m of
where
m = runAlex s lexStream
lexCoreR :: Text -> RLPC RlpcError [Located CoreToken]
lexCoreR = liftRlpcErrs . lexCore
-- | @lexCore@, but the tokens are stripped of location info. Useful for
-- debugging
lexCore' :: Text -> RLPC SrcError [CoreToken]
@@ -194,6 +199,14 @@ data ParseError = ParErrLexical String
| ParErrParse
deriving Show
-- TODO:
instance IsRlpcError SrcError where
liftRlpcErr = RlpcErr . show
-- TODO:
instance IsRlpcError ParseError where
liftRlpcErr = RlpcErr . show
alexEOF :: Alex (Located CoreToken)
alexEOF = Alex $ \ st@(AlexState { alex_pos = AlexPn _ y x }) ->
Right (st, Located y x 0 TokenEOF)

View File

@@ -8,6 +8,7 @@ module Core.Parse
( parseCore
, parseCoreExpr
, parseCoreProg
, parseCoreProgR
, module Core.Lex -- temp convenience
, parseTmp
, SrcError
@@ -229,5 +230,8 @@ insScDef sc = programScDefs %~ (sc:)
singletonScDef :: (Hashable b) => ScDef b -> Program b
singletonScDef sc = insScDef sc mempty
parseCoreProgR :: [Located CoreToken] -> RLPC RlpcError Program'
parseCoreProgR = liftRlpcErrs . parseCoreProg
}

View File

@@ -63,5 +63,5 @@ qCoreProg s = case parseProg (T.pack s) of
Left e -> error (show e)
Right (m,ts) -> lift m
where
parseProg = evalRLPC def . (lexCore >=> parseCoreProg)
parseProg = evalRLPC def . (lexCoreR >=> parseCoreProgR)