2015-07-28 16:32:19 +03:00
|
|
|
|
-- |
|
2015-08-01 19:24:45 +03:00
|
|
|
|
-- Module : Text.Megaparsec.Char
|
|
|
|
|
-- Copyright : © 2015 Megaparsec contributors
|
2015-07-30 19:20:37 +03:00
|
|
|
|
-- © 2007 Paolo Martini
|
|
|
|
|
-- © 1999–2001 Daan Leijen
|
2015-07-28 16:32:19 +03:00
|
|
|
|
-- License : BSD3
|
|
|
|
|
--
|
|
|
|
|
-- Maintainer : Mark Karpov <markkarpov@opmbx.org>
|
2015-07-29 11:38:32 +03:00
|
|
|
|
-- Stability : experimental
|
2015-07-28 16:32:19 +03:00
|
|
|
|
-- Portability : portable
|
|
|
|
|
--
|
|
|
|
|
-- Commonly used character parsers.
|
|
|
|
|
|
2015-08-01 19:24:45 +03:00
|
|
|
|
module Text.Megaparsec.Char
|
2015-09-06 12:22:37 +03:00
|
|
|
|
( -- * Simple parsers
|
|
|
|
|
newline
|
2015-08-12 20:51:06 +03:00
|
|
|
|
, crlf
|
|
|
|
|
, eol
|
|
|
|
|
, tab
|
|
|
|
|
, space
|
2015-09-06 12:22:37 +03:00
|
|
|
|
-- * Categories of characters
|
2015-08-12 20:51:06 +03:00
|
|
|
|
, controlChar
|
|
|
|
|
, spaceChar
|
|
|
|
|
, upperChar
|
|
|
|
|
, lowerChar
|
|
|
|
|
, letterChar
|
|
|
|
|
, alphaNumChar
|
|
|
|
|
, printChar
|
|
|
|
|
, digitChar
|
|
|
|
|
, octDigitChar
|
|
|
|
|
, hexDigitChar
|
|
|
|
|
, markChar
|
|
|
|
|
, numberChar
|
|
|
|
|
, punctuationChar
|
|
|
|
|
, symbolChar
|
|
|
|
|
, separatorChar
|
|
|
|
|
, asciiChar
|
|
|
|
|
, latin1Char
|
|
|
|
|
, charCategory
|
|
|
|
|
, categoryName
|
2015-09-06 12:22:37 +03:00
|
|
|
|
-- * More general parsers
|
2015-08-12 20:51:06 +03:00
|
|
|
|
, char
|
2015-09-06 12:11:18 +03:00
|
|
|
|
, char'
|
2015-08-12 20:51:06 +03:00
|
|
|
|
, anyChar
|
|
|
|
|
, oneOf
|
2015-09-06 12:11:18 +03:00
|
|
|
|
, oneOf'
|
2015-08-12 20:51:06 +03:00
|
|
|
|
, noneOf
|
2015-09-06 12:11:18 +03:00
|
|
|
|
, noneOf'
|
2015-08-12 20:51:06 +03:00
|
|
|
|
, satisfy
|
2015-09-06 12:22:37 +03:00
|
|
|
|
-- * Sequence of characters
|
2015-09-04 15:12:59 +03:00
|
|
|
|
, string
|
|
|
|
|
, string' )
|
2015-07-28 16:32:19 +03:00
|
|
|
|
where
|
|
|
|
|
|
2015-08-01 17:39:20 +03:00
|
|
|
|
import Control.Applicative ((<|>))
|
2015-07-28 16:32:19 +03:00
|
|
|
|
import Data.Char
|
2015-09-06 12:11:18 +03:00
|
|
|
|
import Data.List (nub)
|
2015-08-12 20:00:03 +03:00
|
|
|
|
import Data.Maybe (fromJust)
|
2015-07-28 16:32:19 +03:00
|
|
|
|
|
2015-08-12 15:41:22 +03:00
|
|
|
|
import Text.Megaparsec.Combinator
|
2015-09-14 11:15:31 +03:00
|
|
|
|
import Text.Megaparsec.Error (Message (..))
|
2015-08-01 19:24:45 +03:00
|
|
|
|
import Text.Megaparsec.Pos
|
|
|
|
|
import Text.Megaparsec.Prim
|
2015-08-08 18:17:27 +03:00
|
|
|
|
import Text.Megaparsec.ShowToken
|
2015-07-28 16:32:19 +03:00
|
|
|
|
|
2015-08-12 15:41:22 +03:00
|
|
|
|
-- | Parses a newline character.
|
2015-07-28 16:32:19 +03:00
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
newline :: MonadParsec s m Char => m Char
|
2015-08-08 18:17:27 +03:00
|
|
|
|
newline = char '\n' <?> "newline"
|
2015-07-28 16:32:19 +03:00
|
|
|
|
|
2015-08-12 15:41:22 +03:00
|
|
|
|
-- | Parses a carriage return character followed by a newline
|
|
|
|
|
-- character. Returns sequence of characters parsed.
|
2015-07-28 16:32:19 +03:00
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
crlf :: MonadParsec s m Char => m String
|
2015-08-11 00:21:52 +03:00
|
|
|
|
crlf = string "\r\n"
|
2015-07-28 16:32:19 +03:00
|
|
|
|
|
2015-08-12 15:41:22 +03:00
|
|
|
|
-- | Parses a CRLF (see 'crlf') or LF (see 'newline') end of line.
|
|
|
|
|
-- Returns the sequence of characters parsed.
|
2015-07-28 16:32:19 +03:00
|
|
|
|
--
|
2015-08-12 15:41:22 +03:00
|
|
|
|
-- > eol = (pure <$> newline) <|> crlf
|
2015-07-28 16:32:19 +03:00
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
eol :: MonadParsec s m Char => m String
|
2015-08-11 00:21:52 +03:00
|
|
|
|
eol = (pure <$> newline) <|> crlf <?> "end of line"
|
2015-07-28 16:32:19 +03:00
|
|
|
|
|
2015-08-12 15:41:22 +03:00
|
|
|
|
-- | Parses a tab character.
|
2015-07-28 16:32:19 +03:00
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
tab :: MonadParsec s m Char => m Char
|
2015-07-28 16:32:19 +03:00
|
|
|
|
tab = char '\t' <?> "tab"
|
|
|
|
|
|
2015-08-12 20:00:03 +03:00
|
|
|
|
-- | Skips /zero/ or more white space characters. See also 'skipMany' and
|
|
|
|
|
-- 'spaceChar'.
|
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
space :: MonadParsec s m Char => m ()
|
2015-08-12 20:00:03 +03:00
|
|
|
|
space = skipMany spaceChar
|
2015-08-12 15:41:22 +03:00
|
|
|
|
|
2015-08-12 20:00:03 +03:00
|
|
|
|
-- | Parses control characters, which are the non-printing characters of the
|
|
|
|
|
-- Latin-1 subset of Unicode.
|
2015-08-12 15:41:22 +03:00
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
controlChar :: MonadParsec s m Char => m Char
|
2015-08-12 20:00:03 +03:00
|
|
|
|
controlChar = satisfy isControl <?> "control character"
|
2015-07-28 16:32:19 +03:00
|
|
|
|
|
2015-08-12 20:00:03 +03:00
|
|
|
|
-- | Parses a Unicode space character, and the control characters: tab,
|
|
|
|
|
-- newline, carriage return, form feed, and vertical tab.
|
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
spaceChar :: MonadParsec s m Char => m Char
|
2015-08-12 20:00:03 +03:00
|
|
|
|
spaceChar = satisfy isSpace <?> "white space"
|
|
|
|
|
|
|
|
|
|
-- | Parses an upper-case or title-case alphabetic Unicode character. Title
|
|
|
|
|
-- case is used by a small number of letter ligatures like the
|
|
|
|
|
-- single-character form of Lj.
|
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
upperChar :: MonadParsec s m Char => m Char
|
2015-08-12 20:00:03 +03:00
|
|
|
|
upperChar = satisfy isUpper <?> "uppercase letter"
|
|
|
|
|
|
|
|
|
|
-- | Parses a lower-case alphabetic Unicode character.
|
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
lowerChar :: MonadParsec s m Char => m Char
|
2015-08-12 20:00:03 +03:00
|
|
|
|
lowerChar = satisfy isLower <?> "lowercase letter"
|
|
|
|
|
|
|
|
|
|
-- | Parses alphabetic Unicode characters: lower-case, upper-case and
|
|
|
|
|
-- title-case letters, plus letters of case-less scripts and modifiers
|
|
|
|
|
-- letters.
|
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
letterChar :: MonadParsec s m Char => m Char
|
2015-08-12 20:00:03 +03:00
|
|
|
|
letterChar = satisfy isLetter <?> "letter"
|
|
|
|
|
|
|
|
|
|
-- | Parses alphabetic or numeric digit Unicode characters.
|
|
|
|
|
--
|
|
|
|
|
-- Note that numeric digits outside the ASCII range are parsed by this
|
|
|
|
|
-- parser but not by 'digitChar'. Such digits may be part of identifiers but
|
|
|
|
|
-- are not used by the printer and reader to represent numbers.
|
2015-07-28 16:32:19 +03:00
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
alphaNumChar :: MonadParsec s m Char => m Char
|
2015-08-12 20:00:03 +03:00
|
|
|
|
alphaNumChar = satisfy isAlphaNum <?> "alphanumeric character"
|
2015-07-28 16:32:19 +03:00
|
|
|
|
|
2015-08-12 20:00:03 +03:00
|
|
|
|
-- | Parses printable Unicode characters: letters, numbers, marks,
|
|
|
|
|
-- punctuation, symbols and spaces.
|
2015-07-28 16:32:19 +03:00
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
printChar :: MonadParsec s m Char => m Char
|
2015-08-12 20:00:03 +03:00
|
|
|
|
printChar = satisfy isPrint <?> "printable character"
|
2015-07-28 16:32:19 +03:00
|
|
|
|
|
2015-08-12 20:00:03 +03:00
|
|
|
|
-- | Parses an ASCII digit, i.e between “0” and “9”.
|
2015-07-28 16:32:19 +03:00
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
digitChar :: MonadParsec s m Char => m Char
|
2015-08-12 20:00:03 +03:00
|
|
|
|
digitChar = satisfy isDigit <?> "digit"
|
2015-07-28 16:32:19 +03:00
|
|
|
|
|
2015-08-12 20:00:03 +03:00
|
|
|
|
-- | Parses an octal digit, i.e. between “0” and “7”.
|
2015-07-28 16:32:19 +03:00
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
octDigitChar :: MonadParsec s m Char => m Char
|
2015-08-12 20:00:03 +03:00
|
|
|
|
octDigitChar = satisfy isOctDigit <?> "octal digit"
|
2015-07-28 16:32:19 +03:00
|
|
|
|
|
2015-08-12 20:00:03 +03:00
|
|
|
|
-- | Parses a hexadecimal digit, i.e. between “0” and “9”, or “a” and “f”,
|
|
|
|
|
-- or “A” and “F”.
|
2015-07-28 16:32:19 +03:00
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
hexDigitChar :: MonadParsec s m Char => m Char
|
2015-08-12 20:00:03 +03:00
|
|
|
|
hexDigitChar = satisfy isHexDigit <?> "hexadecimal digit"
|
2015-08-12 15:41:22 +03:00
|
|
|
|
|
2015-08-12 20:00:03 +03:00
|
|
|
|
-- | Parses Unicode mark characters, for example accents and the like, which
|
|
|
|
|
-- combine with preceding characters.
|
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
markChar :: MonadParsec s m Char => m Char
|
2015-08-12 20:00:03 +03:00
|
|
|
|
markChar = satisfy isMark <?> "mark character"
|
|
|
|
|
|
|
|
|
|
-- | Parses Unicode numeric characters, including digits from various
|
|
|
|
|
-- scripts, Roman numerals, et cetera.
|
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
numberChar :: MonadParsec s m Char => m Char
|
2015-08-12 20:00:03 +03:00
|
|
|
|
numberChar = satisfy isNumber <?> "numeric character"
|
|
|
|
|
|
|
|
|
|
-- | Parses Unicode punctuation characters, including various kinds of
|
|
|
|
|
-- connectors, brackets and quotes.
|
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
punctuationChar :: MonadParsec s m Char => m Char
|
2015-08-12 20:00:03 +03:00
|
|
|
|
punctuationChar = satisfy isPunctuation <?> "punctuation"
|
|
|
|
|
|
|
|
|
|
-- | Parses Unicode symbol characters, including mathematical and currency
|
|
|
|
|
-- symbols.
|
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
symbolChar :: MonadParsec s m Char => m Char
|
2015-08-12 20:00:03 +03:00
|
|
|
|
symbolChar = satisfy isSymbol <?> "symbol"
|
|
|
|
|
|
|
|
|
|
-- | Parses Unicode space and separator characters.
|
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
separatorChar :: MonadParsec s m Char => m Char
|
2015-08-12 20:00:03 +03:00
|
|
|
|
separatorChar = satisfy isSeparator <?> "separator"
|
|
|
|
|
|
|
|
|
|
-- | Parses a character from the first 128 characters of the Unicode character set,
|
|
|
|
|
-- corresponding to the ASCII character set.
|
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
asciiChar :: MonadParsec s m Char => m Char
|
2015-08-12 20:00:03 +03:00
|
|
|
|
asciiChar = satisfy isAscii <?> "ASCII character"
|
|
|
|
|
|
|
|
|
|
-- | Parses a character from the first 256 characters of the Unicode
|
|
|
|
|
-- character set, corresponding to the ISO 8859-1 (Latin-1) character set.
|
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
latin1Char :: MonadParsec s m Char => m Char
|
2015-08-12 20:00:03 +03:00
|
|
|
|
latin1Char = satisfy isLatin1 <?> "Latin-1 character"
|
|
|
|
|
|
|
|
|
|
-- | @charCategory cat@ Parses character in Unicode General Category @cat@,
|
|
|
|
|
-- see 'Data.Char.GeneralCategory'.
|
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
charCategory :: MonadParsec s m Char => GeneralCategory -> m Char
|
2015-08-12 20:00:03 +03:00
|
|
|
|
charCategory cat = satisfy ((== cat) . generalCategory) <?> categoryName cat
|
|
|
|
|
|
|
|
|
|
-- | Returns human-readable name of Unicode General Category.
|
|
|
|
|
|
|
|
|
|
categoryName :: GeneralCategory -> String
|
|
|
|
|
categoryName cat =
|
|
|
|
|
fromJust $ lookup cat
|
|
|
|
|
[ (UppercaseLetter , "uppercase letter")
|
|
|
|
|
, (LowercaseLetter , "lowercase letter")
|
|
|
|
|
, (TitlecaseLetter , "titlecase letter")
|
|
|
|
|
, (ModifierLetter , "modifier letter")
|
|
|
|
|
, (OtherLetter , "other letter")
|
|
|
|
|
, (NonSpacingMark , "non-spacing mark")
|
|
|
|
|
, (SpacingCombiningMark, "spacing combining mark")
|
|
|
|
|
, (EnclosingMark , "enclosing mark")
|
|
|
|
|
, (DecimalNumber , "decimal number character")
|
|
|
|
|
, (LetterNumber , "letter number character")
|
|
|
|
|
, (OtherNumber , "other number character")
|
|
|
|
|
, (ConnectorPunctuation, "connector punctuation")
|
|
|
|
|
, (DashPunctuation , "dash punctuation")
|
|
|
|
|
, (OpenPunctuation , "open punctuation")
|
|
|
|
|
, (ClosePunctuation , "close punctuation")
|
|
|
|
|
, (InitialQuote , "initial quote")
|
|
|
|
|
, (FinalQuote , "final quote")
|
|
|
|
|
, (OtherPunctuation , "other punctuation")
|
|
|
|
|
, (MathSymbol , "math symbol")
|
|
|
|
|
, (CurrencySymbol , "currency symbol")
|
|
|
|
|
, (ModifierSymbol , "modifier symbol")
|
|
|
|
|
, (OtherSymbol , "other symbol")
|
|
|
|
|
, (Space , "white space")
|
|
|
|
|
, (LineSeparator , "line separator")
|
|
|
|
|
, (ParagraphSeparator , "paragraph separator")
|
|
|
|
|
, (Control , "control character")
|
|
|
|
|
, (Format , "format character")
|
|
|
|
|
, (Surrogate , "surrogate character")
|
|
|
|
|
, (PrivateUse , "private-use Unicode character")
|
|
|
|
|
, (NotAssigned , "non-assigned Unicode character") ]
|
2015-08-12 15:41:22 +03:00
|
|
|
|
|
2015-07-28 16:32:19 +03:00
|
|
|
|
-- | @char c@ parses a single character @c@.
|
|
|
|
|
--
|
2015-08-12 15:41:22 +03:00
|
|
|
|
-- > semicolon = char ';'
|
2015-07-28 16:32:19 +03:00
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
char :: MonadParsec s m Char => Char -> m Char
|
2015-08-08 18:17:27 +03:00
|
|
|
|
char c = satisfy (== c) <?> showToken c
|
2015-07-28 16:32:19 +03:00
|
|
|
|
|
2015-09-06 12:11:18 +03:00
|
|
|
|
-- | The same as 'char' but case-insensitive. This parser returns actually
|
|
|
|
|
-- parsed character preserving its case.
|
|
|
|
|
--
|
|
|
|
|
-- >>> parseTest (char' 'e') "E"
|
|
|
|
|
-- 'E'
|
|
|
|
|
-- >>> parseTest (char' 'e') "G"
|
|
|
|
|
-- parse error at line 1, column 1:
|
|
|
|
|
-- unexpected 'G'
|
|
|
|
|
-- expecting 'E' or 'e'
|
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
char' :: MonadParsec s m Char => Char -> m Char
|
2015-09-06 12:11:18 +03:00
|
|
|
|
char' = choice . fmap char . extendi . pure
|
|
|
|
|
|
|
|
|
|
-- | Extends given list of characters adding uppercase version of every
|
|
|
|
|
-- lowercase characters and vice versa. Resulting list is guaranteed to have
|
|
|
|
|
-- no duplicates.
|
|
|
|
|
|
|
|
|
|
extendi :: String -> String
|
|
|
|
|
extendi cs = nub (cs >>= f)
|
|
|
|
|
where f c | isLower c = [c, toUpper c]
|
|
|
|
|
| isUpper c = [c, toLower c]
|
|
|
|
|
| otherwise = [c]
|
|
|
|
|
|
2015-07-28 16:32:19 +03:00
|
|
|
|
-- | This parser succeeds for any character. Returns the parsed character.
|
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
anyChar :: MonadParsec s m Char => m Char
|
2015-08-08 18:17:27 +03:00
|
|
|
|
anyChar = satisfy (const True) <?> "character"
|
2015-07-28 16:32:19 +03:00
|
|
|
|
|
2015-08-12 20:00:03 +03:00
|
|
|
|
-- | @oneOf cs@ succeeds if the current character is in the supplied
|
2015-09-06 12:11:18 +03:00
|
|
|
|
-- list of characters @cs@. Returns the parsed character. Note that this
|
|
|
|
|
-- parser doesn't automatically generate “expected” component of error
|
|
|
|
|
-- message, so usually you should label it manually with 'label' or
|
|
|
|
|
-- ('<?>').
|
|
|
|
|
--
|
|
|
|
|
-- See also 'satisfy'.
|
2015-08-12 20:00:03 +03:00
|
|
|
|
--
|
2015-09-06 12:11:18 +03:00
|
|
|
|
-- > digit = oneOf ['0'..'9'] <?> "digit"
|
2015-08-12 20:00:03 +03:00
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
oneOf :: MonadParsec s m Char => String -> m Char
|
2015-08-12 20:00:03 +03:00
|
|
|
|
oneOf cs = satisfy (`elem` cs)
|
|
|
|
|
|
2015-09-06 12:11:18 +03:00
|
|
|
|
-- | The same as 'oneOf', but case-insensitive. Returns the parsed character
|
|
|
|
|
-- preserving its case.
|
|
|
|
|
--
|
|
|
|
|
-- > vowel = oneOf' "aeiou" <?> "vowel"
|
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
oneOf' :: MonadParsec s m Char => String -> m Char
|
2015-09-06 12:11:18 +03:00
|
|
|
|
oneOf' = oneOf . extendi
|
|
|
|
|
|
2015-08-12 20:00:03 +03:00
|
|
|
|
-- | As the dual of 'oneOf', @noneOf cs@ succeeds if the current
|
|
|
|
|
-- character /not/ in the supplied list of characters @cs@. Returns the
|
|
|
|
|
-- parsed character.
|
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
noneOf :: MonadParsec s m Char => String -> m Char
|
2015-08-12 20:00:03 +03:00
|
|
|
|
noneOf cs = satisfy (`notElem` cs)
|
|
|
|
|
|
2015-09-06 12:11:18 +03:00
|
|
|
|
-- | The same as 'noneOf', but case-insensitive.
|
|
|
|
|
--
|
|
|
|
|
-- > consonant = noneOf' "aeiou" <?> "consonant"
|
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
noneOf' :: MonadParsec s m Char => String -> m Char
|
2015-09-06 12:11:18 +03:00
|
|
|
|
noneOf' = noneOf . extendi
|
|
|
|
|
|
2015-07-28 16:32:19 +03:00
|
|
|
|
-- | The parser @satisfy f@ succeeds for any character for which the
|
|
|
|
|
-- supplied function @f@ returns 'True'. Returns the character that is
|
|
|
|
|
-- actually parsed.
|
|
|
|
|
--
|
2015-09-06 12:11:18 +03:00
|
|
|
|
-- > digitChar = satisfy isDigit <?> "digit"
|
|
|
|
|
-- > oneOf cs = satisfy (`elem` cs)
|
2015-07-28 16:32:19 +03:00
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
satisfy :: MonadParsec s m Char => (Char -> Bool) -> m Char
|
2015-08-17 18:58:59 +03:00
|
|
|
|
satisfy f = token nextPos testChar
|
2015-08-12 20:51:06 +03:00
|
|
|
|
where nextPos pos x _ = updatePosChar pos x
|
2015-09-14 11:15:31 +03:00
|
|
|
|
testChar x = if f x
|
|
|
|
|
then Right x
|
|
|
|
|
else Left . pure . Unexpected . showToken $ x
|
2015-07-28 16:32:19 +03:00
|
|
|
|
|
|
|
|
|
-- | @string s@ parses a sequence of characters given by @s@. Returns
|
|
|
|
|
-- the parsed string (i.e. @s@).
|
|
|
|
|
--
|
|
|
|
|
-- > divOrMod = string "div" <|> string "mod"
|
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
string :: MonadParsec s m Char => String -> m String
|
2015-09-04 15:12:59 +03:00
|
|
|
|
string = tokens updatePosString (==)
|
|
|
|
|
|
|
|
|
|
-- | The same as 'string', but case-insensitive. On success returns string
|
|
|
|
|
-- cased as argument of the function.
|
|
|
|
|
--
|
|
|
|
|
-- >>> parseTest (string' "foobar") "foObAr"
|
|
|
|
|
-- "foobar"
|
|
|
|
|
|
2015-09-18 12:33:44 +03:00
|
|
|
|
string' :: MonadParsec s m Char => String -> m String
|
2015-09-04 15:12:59 +03:00
|
|
|
|
string' = tokens updatePosString test
|
|
|
|
|
where test x y = toLower x == toLower y
|