ddc-base 0.3.1.1 → 0.3.2.1
raw patch · 4 files changed
+56/−14 lines, 4 filesdep +deepseqPVP ok
version bump matches the API change (PVP)
Dependencies added: deepseq
API changes (from Hackage documentation)
+ DDC.Base.Parser: data SourcePos
+ DDC.Base.Parser: pTokAsSP :: Eq k => k -> t -> Parser k (t, SourcePos)
+ DDC.Base.Parser: pTokMaybeSP :: (k -> Maybe a) -> Parser k (a, SourcePos)
+ DDC.Base.Parser: pTokSP :: Eq k => k -> Parser k SourcePos
+ DDC.Data.SourcePos: instance NFData SourcePos
Files
- DDC/Base/Parser.hs +46/−9
- DDC/Data/SourcePos.hs +6/−1
- LICENSE +1/−1
- ddc-base.cabal +3/−3
DDC/Base/Parser.hs view
@@ -4,16 +4,18 @@ ( module Text.Parsec , Parser , ParserState (..)+ , D.SourcePos , runTokenParser- , pTokMaybe- , pTokAs- , pTok)+ , pTokMaybe, pTokMaybeSP+ , pTokAs, pTokAsSP+ , pTok, pTokSP) where import DDC.Base.Pretty import DDC.Data.Token+import DDC.Data.SourcePos as D import Data.Functor.Identity-import Text.Parsec-import Text.Parsec as P+import Text.Parsec hiding (SourcePos)+import Text.Parsec as P import Text.Parsec.Error as P @@ -50,22 +52,57 @@ ------------------------------------------------------------------------------- -- | Accept the given token.-pTok :: Eq k => k -> Parser k ()+pTok :: Eq k => k -> Parser k () pTok k = pTokMaybe $ \k' -> if k == k' then Just () else Nothing +-- | Accept the given token, returning its source position.+pTokSP :: Eq k => k -> Parser k D.SourcePos+pTokSP k + = do (_, sp) <- pTokMaybeSP + $ \k' -> if k == k' then Just () else Nothing+ return sp++ -- | Accept a token and return the given value. pTokAs :: Eq k => k -> t -> Parser k t-pTokAs k t = pTok k >> return t+pTokAs k t + = do pTok k+ return t +-- | Accept a token and return the given value, +-- along with the source position of the token.+pTokAsSP :: Eq k => k -> t -> Parser k (t, D.SourcePos)+pTokAsSP k t + = do sp <- pTokSP k+ return (t, sp)++ -- | Accept a token if the function returns `Just`. -pTokMaybe :: (k -> Maybe a) -> Parser k a-pTokMaybe f+pTokMaybe :: (k -> Maybe a) -> Parser k a+pTokMaybe f = do state <- P.getState+ P.token (stateTokenShow state . tokenTok) (takeParsecSourcePos) (f . tokenTok)+++-- | Accept a token if the function return `Just`, +-- also returning the source position of that token.+pTokMaybeSP :: (k -> Maybe a) -> Parser k (a, D.SourcePos)+pTokMaybeSP f+ = do state <- P.getState++ let f' token' + = case f (tokenTok token') of+ Nothing -> Nothing+ Just x -> Just (x, tokenSourcePos token')++ P.token (stateTokenShow state . tokenTok)+ (takeParsecSourcePos)+ f' -------------------------------------------------------------------------------
DDC/Data/SourcePos.hs view
@@ -3,7 +3,7 @@ (SourcePos (..)) where import DDC.Base.Pretty-+import Control.DeepSeq -- | A position in a source file. --@@ -15,6 +15,11 @@ , sourcePosLine :: Int , sourcePosColumn :: Int } deriving (Eq, Show)+++instance NFData SourcePos where+ rnf (SourcePos str l c)+ = rnf str `seq` rnf l `seq` rnf c instance Pretty SourcePos where
LICENSE view
@@ -1,7 +1,7 @@ -------------------------------------------------------------------------------- The Disciplined Disciple Compiler License (MIT style) -Copyrite (K) 2007-2012 The Disciplined Disciple Compiler Strike Force+Copyrite (K) 2007-2013 The Disciplined Disciple Compiler Strike Force All rights reversed. Permission is hereby granted, free of charge, to any person obtaining a copy
ddc-base.cabal view
@@ -1,5 +1,5 @@ Name: ddc-base-Version: 0.3.1.1+Version: 0.3.2.1 License: MIT License-file: LICENSE Author: The Disciplined Disciple Compiler Strike Force@@ -9,7 +9,6 @@ Stability: experimental Category: Compilers/Interpreters Homepage: http://disciple.ouroborus.net-Bug-reports: disciple@ouroborus.net Synopsis: Disciplined Disciple Compiler common utilities. Description: This package re-exports the main external dependencies of @@ -22,7 +21,8 @@ transformers == 0.3.*, containers == 0.5.*, wl-pprint == 1.1.*,- parsec == 3.1.*+ parsec == 3.1.*,+ deepseq == 1.3.* Exposed-modules: DDC.Base.Parser