parsers 0.5.2 → 0.6
raw patch · 5 files changed
+41/−6 lines, 5 files
Files
- parsers.cabal +1/−1
- src/Text/Parser/Expression.hs +4/−0
- src/Text/Parser/Permutation.hs +1/−3
- src/Text/Parser/Token.hs +31/−0
- src/Text/Parser/Token/Style.hs +4/−2
parsers.cabal view
@@ -1,6 +1,6 @@ name: parsers category: Text, Parsing-version: 0.5.2+version: 0.6 license: BSD3 cabal-version: >= 1.10 license-file: LICENSE
src/Text/Parser/Expression.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE DeriveDataTypeable #-} ----------------------------------------------------------------------------- -- | -- Module : Text.Parser.Expression@@ -22,6 +23,8 @@ import Control.Applicative import Text.Parser.Combinators+import Data.Data hiding (Infix, Prefix)+import Data.Ix ----------------------------------------------------------- -- Assoc and OperatorTable@@ -34,6 +37,7 @@ = AssocNone | AssocLeft | AssocRight+ deriving (Eq,Ord,Show,Read,Ix,Enum,Bounded,Data,Typeable) -- | This data type specifies operators that work on values of type @a@. -- An operator is either binary infix or unary prefix or postfix. A
src/Text/Parser/Permutation.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE ExistentialQuantification #-} ----------------------------------------------------------------------------- -- | -- Module : Text.Parser.Permutation@@ -17,9 +18,6 @@ -- Published as a functional pearl at the Haskell Workshop 2001. -- -------------------------------------------------------------------------------{-# LANGUAGE ExistentialQuantification #-}- module Text.Parser.Permutation ( Permutation , permute
src/Text/Parser/Token.hs view
@@ -24,10 +24,12 @@ whiteSpace -- :: TokenParsing m => m () , charLiteral -- :: TokenParsing m => m Char , stringLiteral -- :: TokenParsing m => m String+ , stringLiteral' -- :: TokenParsing m => m String , natural -- :: TokenParsing m => m Integer , integer -- :: TokenParsing m => m Integer , double -- :: TokenParsing m => m Double , naturalOrDouble -- :: TokenParsing m => m (Either Integer Double)+ , integerOrDouble -- :: TokenParsing m => m (Either Integer Double) , symbol -- :: TokenParsing m => String -> m String , symbolic -- :: TokenParsing m => Char -> m Char , parens -- :: TokenParsing m => m a -> m a@@ -130,6 +132,26 @@ escapeGap = skipSome space *> (char '\\' <?> "end of string gap") {-# INLINE stringLiteral #-} +-- | This token parser behaves as 'stringLiteral', but for single-quoted+-- strings.+stringLiteral' :: TokenParsing m => m String+stringLiteral' = token (highlight StringLiteral lit) where+ lit = Prelude.foldr (maybe id (:)) ""+ <$> between (char '\'') (char '\'' <?> "end of string") (many stringChar)+ <?> "string"+ stringChar = Just <$> stringLetter+ <|> stringEscape+ <?> "string character"+ stringLetter = satisfy (\c -> (c /= '\'') && (c /= '\\') && (c > '\026'))++ stringEscape = highlight EscapeCode $ char '\\' *> esc where+ esc = Nothing <$ escapeGap+ <|> Nothing <$ escapeEmpty+ <|> Just <$> escapeCode+ escapeEmpty = char '&'+ escapeGap = skipSome space *> (char '\\' <?> "end of string gap")+{-# INLINE stringLiteral' #-}+ -- | This token parser parses a natural number (a positive whole -- number). Returns the value of the number. The number can be -- specified in 'decimal', 'hexadecimal' or@@ -167,6 +189,15 @@ naturalOrDouble :: TokenParsing m => m (Either Integer Double) naturalOrDouble = token (highlight Number natDouble <?> "number") {-# INLINE naturalOrDouble #-}++-- | This token parser is like 'naturalOrDouble', but handles+-- leading @-@ or @+@.+integerOrDouble :: TokenParsing m => m (Either Integer Double)+integerOrDouble = token (highlight Number iod <?> "number")+ where iod = mneg <$> optional (oneOf "+-") <*> natDouble+ mneg (Just '-') nd = either (Left . negate) (Right . negate) nd+ mneg _ nd = nd+{-# INLINE integerOrDouble #-} -- | Token parser @symbol s@ parses 'string' @s@ and skips -- trailing white space.
src/Text/Parser/Token/Style.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE DeriveDataTypeable #-} ----------------------------------------------------------------------------- -- | -- Module : Text.Parser.Token.Style@@ -37,6 +38,7 @@ import qualified Data.HashSet as HashSet import Data.HashSet (HashSet) import Data.Monoid+import Data.Data import Text.Parser.Combinators import Text.Parser.Char import Text.Parser.Token@@ -49,7 +51,7 @@ , _commentEnd :: String -- ^ String that ends a multiline comment , _commentLine :: String -- ^ String that starts a single line comment , _commentNesting :: Bool -- ^ Can we nest multiline comments?- }+ } deriving (Eq,Ord,Show,Read,Data,Typeable) -- | This is a lens that can edit the string that starts a multiline comment. --@@ -85,7 +87,7 @@ -- | Use java-style comments javaCommentStyle :: CommentStyle-javaCommentStyle = CommentStyle "/*" "*/" "//" True+javaCommentStyle = CommentStyle "/*" "*/" "//" False -- | Use haskell-style comments haskellCommentStyle :: CommentStyle