cosmetic changes (indentation, etc)

This commit is contained in:
mrkkrp 2015-08-12 23:51:06 +06:00
parent 77a54394b5
commit 287a777e6c
20 changed files with 1141 additions and 1159 deletions

View File

@ -40,8 +40,7 @@
-- imported explicitly along with two modules mentioned above.
module Text.Megaparsec
(
-- * Parsers
( -- * Parsers
ParsecT
, Parsec
, token

View File

@ -64,13 +64,6 @@ option x p = p <|> return x
optionMaybe :: Stream s m t => ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe p = option Nothing (Just <$> p)
-- -- | @optional p@ tries to apply parser @p@. It will parse @p@ or nothing.
-- -- It only fails if @p@ fails after consuming input. It discards the result
-- -- of @p@.
-- optional :: Stream s m t => ParsecT s u m a -> ParsecT s u m ()
-- optional p = (p *> return ()) <|> return ()
-- | @between open close p@ parses @open@, followed by @p@ and @close@.
-- Returns the value returned by @p@.
--

View File

@ -43,7 +43,8 @@ import Text.Megaparsec.Pos
-- The fine distinction between different kinds of parse errors allows the
-- system to generate quite good error messages for the user.
data Message = Unexpected !String
data Message
= Unexpected !String
| Expected !String
| Message !String
deriving Show
@ -55,8 +56,7 @@ instance Enum Message where
toEnum _ = error "Text.Megaparsec.Error: toEnum is undefined for Message"
instance Eq Message where
m1 == m2 =
fromEnum m1 == fromEnum m2 && messageString m1 == messageString m2
m1 == m2 = fromEnum m1 == fromEnum m2 && messageString m1 == messageString m2
instance Ord Message where
compare m1 m2 =
@ -157,8 +157,8 @@ mergeError e1@(ParseError pos1 ms1) e2@(ParseError pos2 ms2) =
showMessages :: [Message] -> String
showMessages [] = "unknown parse error"
showMessages ms = intercalate "\n" $
filter (not . null) [unexpected', expected', messages']
showMessages ms =
intercalate "\n" $ filter (not . null) [unexpected', expected', messages']
where (unexpected, ms') = span ((== 0) . fromEnum) ms
(expected, messages) = span ((== 1) . fromEnum) ms'

View File

@ -123,8 +123,7 @@ add perm@(Perm _mf fs) p = Perm Nothing (first : fmap insert fs)
addopt :: Stream s Identity tok => StreamPermParser s st (a -> b) ->
a -> Parsec s st a -> StreamPermParser s st b
addopt perm@(Perm mf fs) x p
= Perm (fmap ($ x) mf) (first:map insert fs)
addopt perm@(Perm mf fs) x p = Perm (fmap ($ x) mf) (first : map insert fs)
where first = Branch perm p
insert (Branch perm' p') = Branch (addopt (mapPerms flip perm') x p) p'

View File

@ -120,8 +120,7 @@ instance Monad m => Stream TL.Text m Char where
--
-- You shouldn't really need to know this. See also: 'Reply'.
data Consumed a = Consumed a
| Empty !a
data Consumed a = Consumed a | Empty !a
-- | This data structure represents an aspect of result of parser's
-- work. The two constructors have the following meaning:
@ -131,8 +130,7 @@ data Consumed a = Consumed a
--
-- You shouldn't really need to know this. See also 'Consumed'.
data Reply s u a = Ok a !(State s u) ParseError
| Error ParseError
data Reply s u a = Ok a !(State s u) ParseError | Error ParseError
-- | @ParsecT s u m a@ is a parser with stream type @s@, user state type @u@,
-- underlying monad @m@ and return type @a@. Parsec is strict in the user
@ -189,8 +187,8 @@ parserBind m k = ParsecT $ \s cok cerr eok eerr ->
-- if (k x) consumes, those go straight up
pcok = cok
pcerr = cerr
-- if (k x) doesn't consume input, but is okay, we still
-- return in the consumed continuation
-- if (k x) doesn't consume input, but is okay, we still return in
-- the consumed continuation
peok x' s' err' = cok x' s' (mergeError err err')
-- if (k x) doesn't consume input, but errors, we return the
-- error in the 'consumed-error' continuation
@ -282,12 +280,9 @@ parserZero = ParsecT $ \s _ _ _ eerr -> eerr $ unknownError s
parserPlus :: ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
{-# INLINE parserPlus #-}
parserPlus m n
= ParsecT $ \s cok cerr eok eerr ->
let
meerr err =
let
neok y s' err' = eok y s' (mergeError err err')
parserPlus m n = ParsecT $ \s cok cerr eok eerr ->
let meerr err =
let neok y s' err' = eok y s' (mergeError err err')
neerr err' = eerr $ mergeError err err'
in unParser n s cok cerr neok neerr
in unParser m s cok cerr eok meerr
@ -295,7 +290,7 @@ parserPlus m n
instance MonadTrans (ParsecT s u) where
lift amb = ParsecT $ \s _ _ eok _ -> do
a <- amb
eok a s $ unknownError s
eok a s (unknownError s)
-- Errors
@ -371,14 +366,13 @@ labels p msgs = ParsecT $ \s cok cerr eok eerr ->
runParserT :: Stream s m t =>
ParsecT s u m a -> u -> SourceName -> s -> m (Either ParseError a)
runParserT p u name s
= do res <- runParsecT p (State s (initialPos name) u)
runParserT p u name s = do
res <- runParsecT p (State s (initialPos name) u)
r <- parserReply res
case r of
Ok x _ _ -> return (Right x)
Error err -> return (Left err)
where parserReply res
= case res of
where parserReply res = case res of
Consumed r -> r
Empty r -> r
@ -510,8 +504,7 @@ tokens :: (Stream s m t, Eq t, ShowToken [t]) =>
-> ParsecT s u m [t]
{-# INLINE tokens #-}
tokens _ [] = ParsecT $ \s _ _ eok _ -> eok [] s $ unknownError s
tokens nextposs tts
= ParsecT $ \(State input pos u) cok cerr _ eerr ->
tokens nextposs tts = ParsecT $ \(State input pos u) cok cerr _ eerr ->
let errExpect x = setErrorMessage (Expected $ showToken tts)
(newErrorMessage (Unexpected x) pos)
@ -589,8 +582,7 @@ unexpectError :: String -> SourcePos -> ParseError
unexpectError msg = newErrorMessage (Unexpected msg)
manyAccum :: (a -> [a] -> [a]) -> ParsecT s u m a -> ParsecT s u m [a]
manyAccum acc p =
ParsecT $ \s cok cerr eok _ ->
manyAccum acc p = ParsecT $ \s cok cerr eok _ ->
let walk xs x s' _ =
unParser p s'
(seq xs $ walk $ acc x xs) -- consumed-ok
@ -600,8 +592,7 @@ manyAccum acc p =
in unParser p s (walk []) cerr manyErr (eok [] s)
manyErr :: forall t . t
manyErr =
error
manyErr = error
"Text.Megaparsec.Prim.many: combinator 'many' is applied to a parser \
\that accepts an empty string."
@ -641,8 +632,8 @@ setParserState st = updateParserState (const st)
-- | @updateParserState f@ applies function @f@ to the parser state.
updateParserState :: (State s u -> State s u) -> ParsecT s u m (State s u)
updateParserState f =
ParsecT $ \s _ _ eok _ -> let s' = f s in eok s' s' $ unknownError s'
updateParserState f = ParsecT $ \s _ _ eok _ ->
let s' = f s in eok s' s' $ unknownError s'
-- User state combinators

View File

@ -113,9 +113,8 @@ data TokenParser s u m =
-- | The lexeme parser parses a legal operator. Returns the name of the
-- operator. This parser will fail on any operators that are reserved
-- operators. Legal operator (start) characters and reserved operators
-- are defined in the 'LanguageDef' that is passed to
-- 'makeTokenParser'.
-- operators. Legal operator (start) characters and reserved operators are
-- defined in the 'LanguageDef' that is passed to 'makeTokenParser'.
, operator :: ParsecT s u m String
@ -135,15 +134,15 @@ data TokenParser s u m =
-- | The lexeme parser parses a literal string. Returns the literal
-- string value. This parsers deals correctly with escape sequences and
-- gaps. The literal string is parsed according to the grammar rules
-- defined in the Haskell report (which matches most programming
-- languages quite closely).
-- defined in the Haskell report (which matches most programming languages
-- quite closely).
, stringLiteral :: ParsecT s u m String
-- | The lexeme parser parses an integer (a whole number). This parser
-- /does not/ parse sign. Returns the value of the number. The number
-- can be specified in 'decimal', 'hexadecimal' or 'octal'. The number
-- is parsed according to the grammar rules in the Haskell report.
-- /does not/ parse sign. Returns the value of the number. The number can
-- be specified in 'decimal', 'hexadecimal' or 'octal'. The number is
-- parsed according to the grammar rules in the Haskell report.
, integer :: ParsecT s u m Integer
@ -176,7 +175,7 @@ data TokenParser s u m =
-- | The lexeme parser parses a floating point value. Returns the value
-- of the number. The number is parsed according to the grammar rules
-- defined in the Haskell report, sign is /not/ parsed, use 'float\'' to
-- defined in the Haskell report, sign is /not/ parsed, use 'float'' to
-- achieve parsing of signed floating point values.
, float :: ParsecT s u m Double
@ -186,8 +185,8 @@ data TokenParser s u m =
, float' :: ParsecT s u m Double
-- | The lexeme parser parses either 'integer' or a 'float'.
-- Returns the value of the number. This parser deals with any overlap
-- in the grammar rules for integers and floats. The number is parsed
-- Returns the value of the number. This parser deals with any overlap in
-- the grammar rules for integers and floats. The number is parsed
-- according to the grammar rules defined in the Haskell report.
, number :: ParsecT s u m (Either Integer Double)
@ -203,13 +202,13 @@ data TokenParser s u m =
-- | @lexeme p@ first applies parser @p@ and than the 'whiteSpace'
-- parser, returning the value of @p@. Every lexical token (lexeme) is
-- defined using @lexeme@, this way every parse starts at a point
-- without white space. Parsers that use @lexeme@ are called /lexeme/
-- parsers in this document.
-- defined using @lexeme@, this way every parse starts at a point without
-- white space. Parsers that use @lexeme@ are called /lexeme/ parsers in
-- this document.
--
-- The only point where the 'whiteSpace' parser should be called
-- explicitly is the start of the main parser in order to skip any
-- leading white space.
-- explicitly is the start of the main parser in order to skip any leading
-- white space.
, lexeme :: forall a. ParsecT s u m a -> ParsecT s u m a

View File

@ -148,8 +148,8 @@ prop_letterChar :: String -> Property
prop_letterChar = checkChar letterChar isAlpha (Just "letter")
prop_alphaNumChar :: String -> Property
prop_alphaNumChar = checkChar alphaNumChar isAlphaNum
(Just "alphanumeric character")
prop_alphaNumChar =
checkChar alphaNumChar isAlphaNum (Just "alphanumeric character")
prop_printChar :: String -> Property
prop_printChar = checkChar printChar isPrint (Just "printable character")
@ -170,8 +170,8 @@ prop_numberChar :: String -> Property
prop_numberChar = checkChar numberChar isNumber (Just "numeric character")
prop_punctuationChar :: String -> Property
prop_punctuationChar = checkChar punctuationChar isPunctuation
(Just "punctuation")
prop_punctuationChar =
checkChar punctuationChar isPunctuation (Just "punctuation")
prop_symbolChar :: String -> Property
prop_symbolChar = checkChar symbolChar isSymbol (Just "symbol")

View File

@ -82,9 +82,9 @@ prop_wellFormedMessages err = wellFormed $ errorMessages err
prop_parseErrorCopy :: ParseError -> Bool
prop_parseErrorCopy err =
foldr addErrorMessage (newErrorUnknown pos) messages == err
foldr addErrorMessage (newErrorUnknown pos) msgs == err
where pos = errorPos err
messages = errorMessages err
msgs = errorMessages err
prop_setErrorPos :: SourcePos -> ParseError -> Bool
prop_setErrorPos pos err =

View File

@ -71,7 +71,8 @@ prop_components pos = pos == copy
where copy = newPos (sourceName pos) (sourceLine pos) (sourceColumn pos)
prop_showFileName :: SourcePos -> Bool
prop_showFileName pos = if null name
prop_showFileName pos =
if null name
then '"'`notElem` shown
else ("\"" ++ name ++ "\"") `isInfixOf` shown
where name = sourceName pos