Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- type Parser = Parsec Void Text
- isIdent :: Text -> Bool
- pIdent :: Parser Text
- pIdent_ :: Maybe Char -> Parser Text
- pInt :: Parser Integer
- pFloat :: Parser Double
- isSpaceOrComma :: Char -> Bool
- lexeme :: Parser a -> Parser a
- symbol :: Text -> Parser Text
- speof :: Parser ()
- sp :: Parser ()
- sp1 :: Parser ()
- spaceOrComment :: Parser ()
- prompt :: Maybe Text -> IO (Maybe Text)
- firstJust :: Monad m => [m (Maybe a)] -> m (Maybe a)
- parseMaybe :: (Ord e, Stream s) => Parsec e s a -> s -> Maybe a
Documentation
isIdent :: Text -> Bool Source #
Is the string an identifier?
NB: only partially checks whether it is a *valid* identifier (i.e. whether it is not e.g. "nil").
>>>
:set -XOverloadedStrings
>>>
isIdent "nil" -- OOPS
True>>>
isIdent ""
False>>>
isIdent "42"
False>>>
isIdent "foo-bar'"
True>>>
isIdent "[子猫]"
True>>>
isIdent "'foo"
False>>>
isIdent "@$%^&*!"
True>>>
isIdent "["
False>>>
isIdent "]"
False>>>
isIdent "x]"
True>>>
isIdent "x["
False>>>
isIdent "x:"
False
isSpaceOrComma :: Char -> Bool Source #
spaceOrComment :: Parser () Source #
parseMaybe :: (Ord e, Stream s) => Parsec e s a -> s -> Maybe a #
runs the parser parseMaybe
p inputp
on input
and returns the
result inside Just
on success and Nothing
on failure. This function
also parses eof
, so if the parser doesn't consume all of its input, it
will fail.
The function is supposed to be useful for lightweight parsing, where error messages (and thus file names) are not important and entire input should be parsed. For example, it can be used when parsing of a single number according to a specification of its format is desired.