-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathParseError.hs
48 lines (42 loc) · 1.63 KB
/
ParseError.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
{-# LANGUAGE DeriveGeneric, DeriveAnyClass #-}
-----------------------------------------------------------------------------
-- |
-- Module : Language.JavaScript.ParseError
-- Based on language-python version by Bernie Pope
-- Copyright : (c) 2009 Bernie Pope
-- License : BSD-style
-- Stability : experimental
-- Portability : ghc
--
-- Error values for the lexer and parser.
-----------------------------------------------------------------------------
module Language.JavaScript.Parser.ParseError
( Error (..)
, ParseError (..)
) where
--import Language.JavaScript.Parser.Pretty
-- import Control.Monad.Error.Class -- Control.Monad.Trans.Except
import Control.DeepSeq (NFData)
import GHC.Generics (Generic)
import Language.JavaScript.Parser.Lexer
import Language.JavaScript.Parser.SrcLocation (TokenPosn)
-- import Language.JavaScript.Parser.Token (Token)
data ParseError
= UnexpectedToken Token
-- ^ An error from the parser. Token found where it should not be.
-- Note: tokens contain their own source span.
| UnexpectedChar Char TokenPosn
-- ^ An error from the lexer. Character found where it should not be.
| StrError String
-- ^ A generic error containing a string message. No source location.
deriving (Eq, Generic, NFData, {- Ord,-} Show)
class Error a where
-- | Creates an exception without a message.
-- The default implementation is @'strMsg' \"\"@.
noMsg :: a
-- | Creates an exception with a message.
-- The default implementation of @'strMsg' s@ is 'noMsg'.
strMsg :: String -> a
instance Error ParseError where
noMsg = StrError ""
strMsg = StrError