tidy things up
This commit is contained in:
@@ -3,7 +3,8 @@ module Core.Lex
|
||||
( lexCore
|
||||
, lexCore'
|
||||
, CoreToken(..)
|
||||
, ParseError(..)
|
||||
, SrcError(..)
|
||||
, SrcErrorType(..)
|
||||
, Located(..)
|
||||
, AlexPosn(..)
|
||||
)
|
||||
@@ -119,19 +120,30 @@ data CoreToken = TokenLet
|
||||
| TokenEOF
|
||||
deriving Show
|
||||
|
||||
data SrcError = SrcError
|
||||
{ _errSpan :: (Int, Int, Int)
|
||||
, _errSeverity :: Severity
|
||||
, _errDiagnostic :: SrcErrorType
|
||||
}
|
||||
deriving Show
|
||||
|
||||
data SrcErrorType = SrcErrLexical String
|
||||
| SrcErrParse
|
||||
deriving Show
|
||||
|
||||
type Lexer = AlexInput -> Int -> Alex (Located CoreToken)
|
||||
|
||||
lexWith :: (String -> CoreToken) -> Lexer
|
||||
lexWith f (AlexPn _ y x,_,_,s) l = pure $ Located y x l (f $ take l s)
|
||||
|
||||
-- | The main lexer driver.
|
||||
lexCore :: String -> RLPC ParseError [Located CoreToken]
|
||||
lexCore :: String -> RLPC SrcError [Located CoreToken]
|
||||
lexCore s = case m of
|
||||
Left e -> addFatal err
|
||||
where err = SrcError
|
||||
{ _errSpan = (0,0,0) -- TODO: location
|
||||
, _errSeverity = Error
|
||||
, _errDiagnostic = ParErrLexical e
|
||||
, _errDiagnostic = SrcErrLexical e
|
||||
}
|
||||
Right ts -> pure ts
|
||||
where
|
||||
@@ -139,7 +151,7 @@ lexCore s = case m of
|
||||
|
||||
-- | @lexCore@, but the tokens are stripped of location info. Useful for
|
||||
-- debugging
|
||||
lexCore' :: String -> RLPC ParseError [CoreToken]
|
||||
lexCore' :: String -> RLPC SrcError [CoreToken]
|
||||
lexCore' s = fmap f <$> lexCore s
|
||||
where f (Located _ _ _ t) = t
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ module Core.Parse
|
||||
, module Core.Lex -- temp convenience
|
||||
, parseTmp
|
||||
, SrcError
|
||||
, ParseError
|
||||
, Module
|
||||
)
|
||||
where
|
||||
@@ -24,7 +23,7 @@ import Data.Default.Class (def)
|
||||
%name parseCoreProg StandaloneProgram
|
||||
%tokentype { Located CoreToken }
|
||||
%error { parseError }
|
||||
%monad { RLPC ParseError }
|
||||
%monad { RLPC SrcError }
|
||||
|
||||
%token
|
||||
let { Located _ _ _ TokenLet }
|
||||
@@ -126,12 +125,12 @@ Con : '(' consym ')' { $2 }
|
||||
| conname { $1 }
|
||||
|
||||
{
|
||||
parseError :: [Located CoreToken] -> RLPC ParseError a
|
||||
parseError :: [Located CoreToken] -> RLPC SrcError a
|
||||
parseError (Located y x l _ : _) = addFatal err
|
||||
where err = SrcError
|
||||
{ _errSpan = (y,x,l)
|
||||
, _errSeverity = Error
|
||||
, _errDiagnostic = ParErrParse
|
||||
, _errDiagnostic = SrcErrParse
|
||||
}
|
||||
|
||||
parseTmp :: IO Module
|
||||
|
||||
Reference in New Issue
Block a user