packages feed

parsers 0.4 → 0.4.1

raw patch · 2 files changed

+20/−18 lines, 2 files

Files

parsers.cabal view
@@ -1,6 +1,6 @@ name:          parsers category:      Text, Parsing-version:       0.4+version:       0.4.1 license:       BSD3 cabal-version: >= 1.10 license-file:  LICENSE
src/Text/Parser/Token.hs view
@@ -22,7 +22,6 @@   (   -- * Token Parsing     whiteSpace      -- :: TokenParsing m => m ()-  , token           -- :: TokenParsing m => m a -> m a   , charLiteral     -- :: TokenParsing m => m Char   , stringLiteral   -- :: TokenParsing m => m String   , natural         -- :: TokenParsing m => m Integer@@ -97,21 +96,6 @@ whiteSpace = someSpace <|> pure () {-# INLINE whiteSpace #-} --- | @token p@ first applies parser @p@ and then the 'whiteSpace'--- parser, returning the value of @p@. Every lexical--- token (token) is defined using @token@, this way every parse--- starts at a point without white space. Parsers that use @token@ are--- called /token/ parsers in this document.------ The only point where the 'whiteSpace' parser should be--- called explicitly is the start of the main parser in order to skip--- any leading white space.------ > mainParser  = sum <$ whiteSpace <*> many (token digit) <* eof-token :: TokenParsing m => m a -> m a-token p = p <* whiteSpace-{-# INLINE token #-}- -- | This token parser parses a single literal character. Returns the -- literal character value. This parsers deals correctly with escape -- sequences. The literal character is parsed according to the grammar@@ -283,7 +267,7 @@   -- any trailing white space. Returns the character \';\'. Overloadable to   -- permit automatic semicolon insertion or Haskell-style layout.   semi :: m Char-  semi = (satisfy (';'==) <?> ";") <* (someSpace <|> pure ())+  semi = token (satisfy (';'==) <?> ";")   {-# INLINE semi #-}    -- | Tag a region of parsed text with a bit of semantic information.@@ -291,6 +275,24 @@   highlight :: Highlight -> m a -> m a   highlight _ a = a   {-# INLINE highlight #-}++  -- | @token p@ first applies parser @p@ and then the 'whiteSpace'+  -- parser, returning the value of @p@. Every lexical+  -- token (token) is defined using @token@, this way every parse+  -- starts at a point without white space. Parsers that use @token@ are+  -- called /token/ parsers in this document.+  --+  -- The only point where the 'whiteSpace' parser should be+  -- called explicitly is the start of the main parser in order to skip+  -- any leading white space.+  --+  -- Alternatively, one might define 'token' as first parsing 'whiteSpace'+  -- and then parser @p@.  By parsing whiteSpace first, the parser is able+  -- to return before parsing additional whiteSpace, improving laziness.+  --+  -- > mainParser  = sum <$ whiteSpace <*> many (token digit) <* eof+  token :: m a -> m a+  token p = p <* (someSpace <|> pure ())  instance (TokenParsing m, MonadPlus m) => TokenParsing (Lazy.StateT s m) where   nesting (Lazy.StateT m) = Lazy.StateT $ nesting . m