alex-tools 0.1.0.0 → 0.1.1.0
raw patch · 3 files changed
+26/−2 lines, 3 filesdep +deepseqPVP ok
version bump matches the API change (PVP)
Dependencies added: deepseq
API changes (from Hackage documentation)
+ AlexTools: instance Control.DeepSeq.NFData AlexTools.SourcePos
+ AlexTools: instance Control.DeepSeq.NFData AlexTools.SourceRange
+ AlexTools: instance Control.DeepSeq.NFData t => Control.DeepSeq.NFData (AlexTools.Lexeme t)
+ AlexTools: prettySourcePos :: SourcePos -> String
+ AlexTools: prettySourceRange :: SourceRange -> String
Files
- ChangeLog.md +4/−0
- alex-tools.cabal +2/−1
- src/AlexTools.hs +20/−1
ChangeLog.md view
@@ -1,5 +1,9 @@ # Revision history for alex-tools +## 0.1.1.0 -- 2016-09-02++* Add `NFData` instances+ ## 0.1.0.0 -- 2016-09-02 * Initial version.
alex-tools.cabal view
@@ -1,5 +1,5 @@ name: alex-tools-version: 0.1.0.0+version: 0.1.1.0 synopsis: A set of functions for a common use case of Alex. description: This captures a common patter for using Alex. license: ISC@@ -21,6 +21,7 @@ other-extensions: TemplateHaskell build-depends: base >=4.7 && <4.10, text >=1.2 && <1.3,+ deepseq >=1.3 && <1.5, template-haskell >=2.9.0 && <2.12 hs-source-dirs: src ghc-options: -Wall
src/AlexTools.hs view
@@ -5,6 +5,7 @@ , Lexeme(..) , SourcePos(..), startPos, beforeStartPos , SourceRange(..)+ , prettySourcePos, prettySourceRange , HasRange(..) , (<->) , moveSourcePos@@ -37,6 +38,7 @@ ) where +import Control.DeepSeq import Data.Word(Word8) import Data.Text(Text) import qualified Data.Text as Text@@ -52,12 +54,22 @@ , lexemeRange :: !SourceRange } deriving (Show, Eq) +instance NFData t => NFData (Lexeme t) where+ rnf (Lexeme x y z) = rnf (x,y,z)+ data SourcePos = SourcePos { sourceIndex :: !Int , sourceLine :: !Int , sourceColumn :: !Int } deriving (Show, Eq) +prettySourcePos :: SourcePos -> String+prettySourcePos x = show (sourceLine x) ++ ":" ++ show (sourceColumn x)+++instance NFData SourcePos where+ rnf (SourcePos x y z) = rnf (x,y,z)+ -- | Update a 'SourcePos' for a particular matched character moveSourcePos :: Char -> SourcePos -> SourcePos moveSourcePos c p = SourcePos { sourceIndex = sourceIndex p + 1@@ -80,6 +92,13 @@ , sourceTo :: !SourcePos } deriving (Show, Eq) +prettySourceRange :: SourceRange -> String+prettySourceRange x = prettySourcePos (sourceFrom x) ++ "--" +++ prettySourcePos (sourceTo x)++instance NFData SourceRange where+ rnf (SourceRange x y) = rnf (x,y)+ class HasRange t where range :: t -> SourceRange @@ -225,7 +244,7 @@ -- | Generate a function to use an Alex lexer.--- The expression is of type @LexerConfig s t -> Input -> s -> [Lexeme t]@+-- The expression is of type @LexerConfig s t -> Input -> [Lexeme t]@ makeLexer :: ExpQ makeLexer = do let local = do n <- newName "x"