Skip to content

Commit d43a0ca

Browse files
feat(parser): add Generic and NFData to parser support types
Extends PR #122 implementation to parser support modules: - Token.hs: Add Generic/NFData to CommentAnnotation and Token types - SrcLocation.hs: Add Generic/NFData to TokenPosn type - ParseError.hs: Add Generic/NFData to ParseError type All modules now include required language extensions and imports for complete Generic and NFData support across the parser.
1 parent 2bb838d commit d43a0ca

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

src/Language/JavaScript/Parser/ParseError.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE DeriveGeneric, DeriveAnyClass #-}
12
-----------------------------------------------------------------------------
23
-- |
34
-- Module : Language.JavaScript.ParseError
@@ -17,6 +18,8 @@ module Language.JavaScript.Parser.ParseError
1718

1819
--import Language.JavaScript.Parser.Pretty
1920
-- import Control.Monad.Error.Class -- Control.Monad.Trans.Except
21+
import Control.DeepSeq (NFData)
22+
import GHC.Generics (Generic)
2023
import Language.JavaScript.Parser.Lexer
2124
import Language.JavaScript.Parser.SrcLocation (TokenPosn)
2225
-- import Language.JavaScript.Parser.Token (Token)
@@ -29,7 +32,7 @@ data ParseError
2932
-- ^ An error from the lexer. Character found where it should not be.
3033
| StrError String
3134
-- ^ A generic error containing a string message. No source location.
32-
deriving (Eq, {- Ord,-} Show)
35+
deriving (Eq, Generic, NFData, {- Ord,-} Show)
3336

3437
class Error a where
3538
-- | Creates an exception without a message.

src/Language/JavaScript/Parser/SrcLocation.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
{-# LANGUAGE DeriveDataTypeable #-}
1+
{-# LANGUAGE DeriveDataTypeable, DeriveGeneric, DeriveAnyClass #-}
22
module Language.JavaScript.Parser.SrcLocation (
33
TokenPosn(..)
44
, tokenPosnEmpty
55
) where
66

7+
import Control.DeepSeq (NFData)
78
import Data.Data
9+
import GHC.Generics (Generic)
810

911
-- | `TokenPosn' records the location of a token in the input text. It has three
1012
-- fields: the address (number of characters preceding the token), line number
@@ -14,7 +16,7 @@ import Data.Data
1416
data TokenPosn = TokenPn !Int -- address (number of characters preceding the token)
1517
!Int -- line number
1618
!Int -- column
17-
deriving (Eq,Show, Read, Data, Typeable)
19+
deriving (Eq, Generic, NFData, Show, Read, Data, Typeable)
1820

1921
tokenPosnEmpty :: TokenPosn
2022
tokenPosnEmpty = TokenPn 0 0 0

src/Language/JavaScript/Parser/Token.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{-# LANGUAGE CPP, DeriveDataTypeable #-}
1+
{-# LANGUAGE CPP, DeriveDataTypeable, DeriveGeneric, DeriveAnyClass #-}
22
-----------------------------------------------------------------------------
33
-- |
44
-- Module : Language.Python.Common.Token
@@ -23,14 +23,16 @@ module Language.JavaScript.Parser.Token
2323
-- TokenClass (..),
2424
) where
2525

26+
import Control.DeepSeq (NFData)
2627
import Data.Data
28+
import GHC.Generics (Generic)
2729
import Language.JavaScript.Parser.SrcLocation
2830

2931
data CommentAnnotation
3032
= CommentA TokenPosn String
3133
| WhiteSpace TokenPosn String
3234
| NoComment
33-
deriving (Eq, Show, Typeable, Data, Read)
35+
deriving (Eq, Generic, NFData, Show, Typeable, Data, Read)
3436

3537
-- | Lexical tokens.
3638
-- Each may be annotated with any comment occurring between the prior token and this one
@@ -178,7 +180,7 @@ data Token
178180
| AsToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
179181
| TailToken { tokenSpan :: !TokenPosn, tokenComment :: ![CommentAnnotation] } -- ^ Stuff between last JS and EOF
180182
| EOFToken { tokenSpan :: !TokenPosn, tokenComment :: ![CommentAnnotation] } -- ^ End of file
181-
deriving (Eq, Show, Typeable)
183+
deriving (Eq, Generic, NFData, Show, Typeable)
182184

183185

184186
-- | Produce a string from a token containing detailed information. Mainly intended for debugging.

0 commit comments

Comments
 (0)