parsec1 1.0.0.5 → 1.0.0.6
raw patch · 3 files changed
+29/−38 lines, 3 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Text.ParserCombinators.Parsec.Prim: instance Alternative (GenParser tok st)
+ Text.ParserCombinators.Parsec.Prim: instance Applicative (GenParser tok st)
- Text.ParserCombinators.Parsec.Prim: (<|>) :: GenParser tok st a -> GenParser tok st a -> GenParser tok st a
+ Text.ParserCombinators.Parsec.Prim: (<|>) :: Alternative f => forall a. f a -> f a -> f a
- Text.ParserCombinators.Parsec.Prim: many :: GenParser tok st a -> GenParser tok st [a]
+ Text.ParserCombinators.Parsec.Prim: many :: Alternative f => forall a. f a -> f [a]
Files
- Text/ParserCombinators/Parsec/Pos.hs +13/−13
- Text/ParserCombinators/Parsec/Prim.hs +14/−23
- parsec1.cabal +2/−2
Text/ParserCombinators/Parsec/Pos.hs view
@@ -3,17 +3,17 @@ -- Module : Text.ParserCombinators.Parsec.Pos -- Copyright : (c) Daan Leijen 1999-2001 -- License : BSD-style (see the file libraries/parsec/LICENSE)--- +-- -- Maintainer : Antoine Latter <aslatter@gmail.com> -- Stability : provisional -- Portability : portable -- -- Textual source positions.--- +-- ----------------------------------------------------------------------------- module Text.ParserCombinators.Parsec.Pos- ( SourceName, Line, Column + ( SourceName, Line, Column , SourcePos , sourceLine, sourceColumn, sourceName , incSourceLine, incSourceColumn@@ -25,7 +25,7 @@ ----------------------------------------------------------- -- Source Positions, a file name, a line and a column. -- upper left is (1,1)------------------------------------------------------------ +----------------------------------------------------------- type SourceName = String type Line = Int type Column = Int@@ -35,8 +35,8 @@ -- a column number. @SourcePos@ is an instance of the 'Show', 'Eq' and -- 'Ord' class. data SourcePos = SourcePos SourceName !Line !Column- deriving (Eq,Ord)- + deriving (Eq,Ord)+ -- | Create a new 'SourcePos' with the given source name, -- line number and column number. newPos :: SourceName -> Line -> Column -> SourcePos@@ -51,7 +51,7 @@ -- | Extracts the name of the source from a source position. sourceName :: SourcePos -> SourceName-sourceName (SourcePos name line column) = name +sourceName (SourcePos name line column) = name -- | Extracts the line number from a source position. sourceLine :: SourcePos -> Line@@ -89,21 +89,21 @@ = forcePos (foldl updatePosChar pos string) updatePosChar :: SourcePos -> Char -> SourcePos-updatePosChar pos@(SourcePos name line column) c +updatePosChar pos@(SourcePos name line column) c = forcePos $ case c of '\n' -> SourcePos name (line+1) 1 '\t' -> SourcePos name line (column + 8 - ((column-1) `mod` 8)) _ -> SourcePos name line (column + 1)- -forcePos :: SourcePos -> SourcePos ++forcePos :: SourcePos -> SourcePos forcePos pos@(SourcePos name line column) = seq line (seq column (pos)) -------------------------------------------------------------- Show positions ------------------------------------------------------------ +-- Show positions+----------------------------------------------------------- instance Show SourcePos where show (SourcePos name line column) | null name = showLineColumn@@ -111,4 +111,4 @@ where showLineColumn = "(line " ++ show line ++ ", column " ++ show column ++- ")" + ")"
Text/ParserCombinators/Parsec/Prim.hs view
@@ -42,6 +42,7 @@ import Prelude import Text.ParserCombinators.Parsec.Pos import Text.ParserCombinators.Parsec.Error+import Control.Applicative import Control.Monad -----------------------------------------------------------@@ -50,7 +51,6 @@ -- <|> is the choice operator ----------------------------------------------------------- infix 0 <?>-infixr 1 <|> -- | The parser @p <?> msg@ behaves as parser @p@, but whenever the -- parser @p@ fails /without consuming any input/, it replaces expect@@ -66,21 +66,6 @@ (<?>) :: GenParser tok st a -> String -> GenParser tok st a p <?> msg = label p msg --- | This combinator implements choice. The parser @p \<|> q@ first--- applies @p@. If it succeeds, the value of @p@ is returned. If @p@--- fails /without consuming any input/, parser @q@ is tried. This--- combinator is defined equal to the 'mplus' member of the 'MonadPlus'--- class and the ('Control.Applicative.<|>') member of 'Control.Applicative.Alternative'.------ The parser is called /predictive/ since @q@ is only tried when--- parser @p@ didn't consume any input (i.e.. the look ahead is 1).--- This non-backtracking behaviour allows for both an efficient--- implementation of the parser combinators and the generation of good--- error messages.-(<|>) :: GenParser tok st a -> GenParser tok st a -> GenParser tok st a-p1 <|> p2 = mplus p1 p2-- ----------------------------------------------------------- -- User state combinators -----------------------------------------------------------@@ -137,11 +122,11 @@ } -- | Returns the full parser state as a 'State' record.-getParserState :: GenParser tok st (State tok st)+getParserState :: GenParser tok st (State tok st) getParserState = updateParserState id -- | @setParserState st@ set the full parser state to @st@.-setParserState :: State tok st -> GenParser tok st (State tok st)+setParserState :: State tok st -> GenParser tok st (State tok st) setParserState st = updateParserState (const st) @@ -256,6 +241,10 @@ p >>= f = parsecBind p f fail msg = parsecFail msg +instance Applicative (GenParser tok st) where+ pure = return+ (<*>) = ap+ parsecReturn :: a -> GenParser tok st a parsecReturn x = Parser (\state -> Empty (Ok x state (unknownError state)))@@ -299,6 +288,10 @@ mzero = parsecZero mplus p1 p2 = parsecPlus p1 p2 +instance Alternative (GenParser tok st) where+ (<|>) = mplus+ empty = mzero+ many = manyAux pzero :: GenParser tok st a pzero = parsecZero@@ -515,15 +508,15 @@ -- they will overflow the stack on large inputs ----------------------------------------------------------- --- | @many p@ applies the parser @p@ /zero/ or more times. Returns a+-- | @manyAux p@ applies the parser @p@ /zero/ or more times. Returns a -- list of the returned values of @p@. -- -- > identifier = do{ c <- letter -- > ; cs <- many (alphaNum <|> char '_') -- > ; return (c:cs) -- > }-many :: GenParser tok st a -> GenParser tok st [a]-many p+manyAux :: GenParser tok st a -> GenParser tok st [a]+manyAux p = do{ xs <- manyAccum (:) p ; return (reverse xs) }@@ -596,5 +589,3 @@ | otherwise = Empty (errExpect [c] ) in walk1 s input)--
parsec1.cabal view
@@ -1,10 +1,10 @@ cabal-version: >= 1.2 name: parsec1-version: 1.0.0.5+version: 1.0.0.6 license: BSD3 license-file: LICENSE author: Daan Leijen <daan@cs.uu.nl>-maintainer: Christian Maeder <Christian.Maeder@dfki.de>+maintainer: c.maeder@jacobs-university.de homepage: http://www.cs.uu.nl/~daan/parsec.html category: Parsing synopsis: Portable monadic parser combinators