packages feed

chatty 0.5.5.0 → 0.5.5.1

raw patch · 2 files changed

+94/−2 lines, 2 files

Files

+ Text/Chatty/Parser.hs view
@@ -0,0 +1,92 @@+{-+  This module is part of Chatty.+  Copyleft (c) 2014 Marvin Cohrs++  All wrongs reversed. Sharing is an act of love, not crime.+  Please share Antisplice with everyone you like.++  Chatty is free software: you can redistribute it and/or modify+  it under the terms of the GNU Affero General Public License as published by+  the Free Software Foundation, either version 3 of the License, or+  (at your option) any later version.++  Chatty is distributed in the hope that it will be useful,+  but WITHOUT ANY WARRANTY; without even the implied warranty of+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+  GNU Affero General Public License for more details.++  You should have received a copy of the GNU Affero General Public License+  along with Chatty. If not, see <http://www.gnu.org/licenses/>.+-}++module Text.Chatty.Parser where++import Control.Monad+import Data.Char+import Text.Chatty.Scanner++class MonadScanner m => MonadParser m where+  pabort :: m a+  (??) :: Eq a => m a -> m a -> m a+  (???) :: m a -> m a -> m a+  ptry :: MonadPlus n => m a -> m (n a)++request :: MonadScanner m => m Char+request = mscan1++match :: MonadParser m => Char -> m Char+match c = do+  k <- request+  if k == c then return c else pabort++matchs :: MonadParser m => String -> m String+matchs [] = return []+matchs (c:cs) = do+  match c+  matchs cs+  return (c:cs)++white :: MonadParser m => m Char+white = do+  k <- request+  if isSpace k then return k else pabort++digit :: MonadParser m => m Int+digit = do+  k <- request+  if isDigit k then return (read [k]) else pabort++alpha :: MonadParser m => m Char+alpha = do+  k <- request+  if isAlpha k then return k else pabort++anum :: MonadParser m => m Char+anum = do+  k <- request+  if isAlphaNum k then return k else pabort++possibly :: MonadParser m => m a -> m (Maybe a)+possibly f = liftM Just f ??? return Nothing++many :: MonadParser m => m a -> m [a]+many f = do+  x <- possibly f+  case x of+    Nothing -> return []+    Just x -> do+      xs <- many f+      return (x : xs)++some :: MonadParser m => m a -> m [a]+some f = do+  x <- f+  xs <- many f+  return (x : xs)++number :: MonadParser m => m Int+number = do+  many white+  ds <- some digit+  many white+  return $ foldl (\k n -> k * 10 + n) 0 ds
chatty.cabal view
@@ -10,7 +10,7 @@ -- PVP summary:      +-+------- breaking API changes --                   | | +----- non-breaking API additions --                   | | | +--- code changes with no API change-version:             0.5.5.0+version:             0.5.5.1  -- A short (one-line) description of the package. synopsis:            Some monad transformers and typeclasses to simplify I/O on a transformer stack.@@ -48,7 +48,7 @@  library   -- Modules exported by the library.-  exposed-modules:     Text.Chatty.Expansion, System.Chatty.Commands, System.Chatty.Spawn, Text.Chatty.Printer, Text.Chatty.Finalizer, Text.Chatty.Templates, Text.Chatty.Scanner, Text.Chatty.Interactor, System.Chatty.Spawn.Overlay, System.Chatty.Spawn.Builtins, Text.Chatty.Interactor.Templates, System.Chatty.Misc, Text.Chatty.Extended.Printer, Text.Chatty.Extended.HTML, Text.Chatty.Extended.ANSI, Text.Chatty.Expansion.Vars, Text.Chatty.Expansion.History, Text.Chatty.Channel.Printer, Text.Chatty.Channel.Broadcast, Text.Chatty.Scanner.Buffered, Text.Chatty.Typograph, Text.Chatty.Parser.Nondeterministic+  exposed-modules:     Text.Chatty.Expansion, System.Chatty.Commands, System.Chatty.Spawn, Text.Chatty.Printer, Text.Chatty.Finalizer, Text.Chatty.Templates, Text.Chatty.Scanner, Text.Chatty.Interactor, System.Chatty.Spawn.Overlay, System.Chatty.Spawn.Builtins, Text.Chatty.Interactor.Templates, System.Chatty.Misc, Text.Chatty.Extended.Printer, Text.Chatty.Extended.HTML, Text.Chatty.Extended.ANSI, Text.Chatty.Expansion.Vars, Text.Chatty.Expansion.History, Text.Chatty.Channel.Printer, Text.Chatty.Channel.Broadcast, Text.Chatty.Scanner.Buffered, Text.Chatty.Typograph, Text.Chatty.Parser.Nondeterministic, Text.Chatty.Parser      -- Modules included in this library but not exported.   -- other-modules: