packages feed

headed-megaparsec 0.1.0.1 → 0.1.0.2

raw patch · 2 files changed

+27/−17 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

headed-megaparsec.cabal view
@@ -1,5 +1,5 @@ name: headed-megaparsec-version: 0.1.0.1+version: 0.1.0.2 category: Parsers, Parsing, Megaparsec synopsis: More informative parser homepage: https://github.com/nikita-volkov/headed-megaparsec
library/HeadedMegaparsec.hs view
@@ -43,31 +43,41 @@  ==__Examples__ +>>> import qualified Text.Megaparsec as M+>>> import qualified Text.Megaparsec.Char as M+>>> import qualified Text.Megaparsec.Char.Lexer as ML >>> :{   let-    select :: HeadedParsec Void Text (Maybe [Either Char Int], Maybe Int)+    select :: HeadedParsec Void String (Maybe [Either Char Int], Maybe Int)     select = do-      head (string' "select")-      _targets <- optional (head space1 *> targets)-      _limit <- optional (head space1 *> limit)+      string' "select"+      endHead+      _targets <- optional (space1 *> targets)+      _limit <- optional (space1 *> limit)       return (_targets, _limit)       where+        -- Lifted versions of basic parsers:+        char = parse . M.char+        space = parse M.space+        space1 = parse M.space1+        decimal = parse ML.decimal+        string' = parse . M.string'+        -- Syntax parsers:         targets = sepBy1 target commaSeparator-        target =-          head (Left <$> char '*') <|>-          head (Right <$> Lexer.decimal)-        commaSeparator = head (space *> char ',' *> space)-        limit =-          head (string' "limit" *> space1) *>-          tail Lexer.decimal-    test :: Text -> IO ()-    test = parseTest (toParsec select <* eof)+        target = Left <$> char '*' <|> Right <$> decimal+        commaSeparator = space *> char ',' *> endHead *> space+        limit = string' "limit" *> endHead *> space1 *> decimal+    test :: String -> IO ()+    test = M.parseTest (toParsec select <* M.eof) :}  >>> test "select 1, "-...-unexpected ','-...+1:11:+  |+1 | select 1, +  |           ^+unexpected end of input+expecting '*', integer, or white space  >>> test "select limit " ...