{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE Strict #-} module Language.Cimple.Parser.Error ( parseError ) where import Data.Aeson (encode) import qualified Data.ByteString.Lazy.Char8 as LBSC import Data.Text (Text) import Language.Cimple.Lexer (Alex, Lexeme (..), ParseError (..), alexError, getContext) import Language.Cimple.Tokens (LexemeClass (..)) parseError :: (Lexeme Text, [String]) -> Alex a parseError :: (Lexeme Text, [String]) -> Alex a parseError (l :: Lexeme Text l@(L AlexPosn p LexemeClass _ Text _), [String] options) = do [Context] ctx <- Alex [Context] getContext String -> Alex a forall a. String -> Alex a alexError (String -> Alex a) -> String -> Alex a forall a b. (a -> b) -> a -> b $ ByteString -> String LBSC.unpack (ParseError -> ByteString forall a. ToJSON a => a -> ByteString encode (AlexPosn -> [Context] -> [String] -> Lexeme Text -> ParseError ParseError AlexPosn p [Context] ctx [String] options Lexeme Text l))