{-# LANGUAGE FlexibleContexts#-}
module Data.Rewriting.Utils.Parse (
lex,
par,
ident
) where
import Control.Monad
import Prelude hiding (lex)
import Text.Parsec
import Data.Char (isSpace)
lex :: Stream s m Char => ParsecT s u m a -> ParsecT s u m a
lex p = do { x <- p; spaces; return x }
par :: Stream s m Char => ParsecT s u m a -> ParsecT s u m a
par = between (lex$char '(') (lex$char ')')
ident :: Stream s m Char => String -> [String] -> ParsecT s u m String
ident tabooChars tabooWords = try $ do
s <- many1 (satisfy (\c -> not (isSpace c) && c `notElem` tabooChars))
guard (s `notElem` tabooWords)
return s