koneko-0.0.2: a concatenative not-quite-lisp for kittens
Safe HaskellNone
LanguageHaskell2010

Koneko.Misc

Synopsis

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

pIdent :: Parser Text Source #

NB: also matches float and int

firstJust :: Monad m => [m (Maybe a)] -> m (Maybe a) Source #

parseMaybe :: (Ord e, Stream s) => Parsec e s a -> s -> Maybe a #

parseMaybe p input runs the parser p 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.