{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
module Text.Regex.TDFA.ReadRegex (parseRegex) where
import Text.Regex.TDFA.Pattern
import Text.ParserCombinators.Parsec((<|>), (<?>),
unexpected, try, runParser, many, getState, setState, CharParser, ParseError,
sepBy1, option, notFollowedBy, many1, lookAhead, eof, between,
string, noneOf, digit, char, anyChar)
import Control.Monad(liftM, when, guard)
import qualified Data.Set as Set(fromList)
data BracketElement = BEChar Char | BEChars String | BEColl String | BEEquiv String | BEClass String
parseRegex :: String -> Either ParseError (Pattern,(GroupIndex,DoPa))
parseRegex :: String -> Either ParseError (Pattern, (GroupIndex, DoPa))
parseRegex String
x = GenParser
Char (GroupIndex, GroupIndex) (Pattern, (GroupIndex, DoPa))
-> (GroupIndex, GroupIndex)
-> String
-> String
-> Either ParseError (Pattern, (GroupIndex, DoPa))
forall tok st a.
GenParser tok st a -> st -> String -> [tok] -> Either ParseError a
runParser (do Pattern
pat <- CharParser (GroupIndex, GroupIndex) Pattern
p_regex
ParsecT String (GroupIndex, GroupIndex) Identity ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
(GroupIndex
lastGroupIndex,GroupIndex
lastDopa) <- ParsecT
String (GroupIndex, GroupIndex) Identity (GroupIndex, GroupIndex)
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
(Pattern, (GroupIndex, DoPa))
-> GenParser
Char (GroupIndex, GroupIndex) (Pattern, (GroupIndex, DoPa))
forall (m :: * -> *) a. Monad m => a -> m a
return (Pattern
pat,(GroupIndex
lastGroupIndex,GroupIndex -> DoPa
DoPa GroupIndex
lastDopa))) (GroupIndex
0,GroupIndex
0) String
x String
x
p_regex :: CharParser (GroupIndex,Int) Pattern
p_regex :: CharParser (GroupIndex, GroupIndex) Pattern
p_regex = ([Pattern] -> Pattern)
-> ParsecT String (GroupIndex, GroupIndex) Identity [Pattern]
-> CharParser (GroupIndex, GroupIndex) Pattern
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM [Pattern] -> Pattern
POr (ParsecT String (GroupIndex, GroupIndex) Identity [Pattern]
-> CharParser (GroupIndex, GroupIndex) Pattern)
-> ParsecT String (GroupIndex, GroupIndex) Identity [Pattern]
-> CharParser (GroupIndex, GroupIndex) Pattern
forall a b. (a -> b) -> a -> b
$ CharParser (GroupIndex, GroupIndex) Pattern
-> ParsecT String (GroupIndex, GroupIndex) Identity Char
-> ParsecT String (GroupIndex, GroupIndex) Identity [Pattern]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepBy1 CharParser (GroupIndex, GroupIndex) Pattern
p_branch (Char -> ParsecT String (GroupIndex, GroupIndex) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'|')
p_branch :: CharParser (GroupIndex, GroupIndex) Pattern
p_branch = ([Pattern] -> Pattern)
-> ParsecT String (GroupIndex, GroupIndex) Identity [Pattern]
-> CharParser (GroupIndex, GroupIndex) Pattern
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM [Pattern] -> Pattern
PConcat (ParsecT String (GroupIndex, GroupIndex) Identity [Pattern]
-> CharParser (GroupIndex, GroupIndex) Pattern)
-> ParsecT String (GroupIndex, GroupIndex) Identity [Pattern]
-> CharParser (GroupIndex, GroupIndex) Pattern
forall a b. (a -> b) -> a -> b
$ CharParser (GroupIndex, GroupIndex) Pattern
-> ParsecT String (GroupIndex, GroupIndex) Identity [Pattern]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 CharParser (GroupIndex, GroupIndex) Pattern
p_piece
p_piece :: CharParser (GroupIndex, GroupIndex) Pattern
p_piece = (CharParser (GroupIndex, GroupIndex) Pattern
p_anchor CharParser (GroupIndex, GroupIndex) Pattern
-> CharParser (GroupIndex, GroupIndex) Pattern
-> CharParser (GroupIndex, GroupIndex) Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> CharParser (GroupIndex, GroupIndex) Pattern
p_atom) CharParser (GroupIndex, GroupIndex) Pattern
-> (Pattern -> CharParser (GroupIndex, GroupIndex) Pattern)
-> CharParser (GroupIndex, GroupIndex) Pattern
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Pattern -> CharParser (GroupIndex, GroupIndex) Pattern
forall u. Pattern -> ParsecT String u Identity Pattern
p_post_atom
p_atom :: CharParser (GroupIndex, GroupIndex) Pattern
p_atom = CharParser (GroupIndex, GroupIndex) Pattern
p_group CharParser (GroupIndex, GroupIndex) Pattern
-> CharParser (GroupIndex, GroupIndex) Pattern
-> CharParser (GroupIndex, GroupIndex) Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> CharParser (GroupIndex, GroupIndex) Pattern
forall a. ParsecT String (a, GroupIndex) Identity Pattern
p_bracket CharParser (GroupIndex, GroupIndex) Pattern
-> CharParser (GroupIndex, GroupIndex) Pattern
-> CharParser (GroupIndex, GroupIndex) Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> CharParser (GroupIndex, GroupIndex) Pattern
forall a. ParsecT String (a, GroupIndex) Identity Pattern
p_char CharParser (GroupIndex, GroupIndex) Pattern
-> String -> CharParser (GroupIndex, GroupIndex) Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"an atom"
group_index :: CharParser (GroupIndex,Int) (Maybe GroupIndex)
group_index :: CharParser (GroupIndex, GroupIndex) (Maybe GroupIndex)
group_index = do
(GroupIndex
gi,GroupIndex
ci) <- ParsecT
String (GroupIndex, GroupIndex) Identity (GroupIndex, GroupIndex)
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
let index :: GroupIndex
index = GroupIndex -> GroupIndex
forall a. Enum a => a -> a
succ GroupIndex
gi
(GroupIndex, GroupIndex)
-> ParsecT String (GroupIndex, GroupIndex) Identity ()
forall (m :: * -> *) u s. Monad m => u -> ParsecT s u m ()
setState (GroupIndex
index,GroupIndex
ci)
Maybe GroupIndex
-> CharParser (GroupIndex, GroupIndex) (Maybe GroupIndex)
forall (m :: * -> *) a. Monad m => a -> m a
return (GroupIndex -> Maybe GroupIndex
forall a. a -> Maybe a
Just GroupIndex
index)
p_group :: CharParser (GroupIndex, GroupIndex) Pattern
p_group = ParsecT String (GroupIndex, GroupIndex) Identity Char
-> ParsecT String (GroupIndex, GroupIndex) Identity Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (Char -> ParsecT String (GroupIndex, GroupIndex) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'(') ParsecT String (GroupIndex, GroupIndex) Identity Char
-> CharParser (GroupIndex, GroupIndex) Pattern
-> CharParser (GroupIndex, GroupIndex) Pattern
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> do
Maybe GroupIndex
index <- CharParser (GroupIndex, GroupIndex) (Maybe GroupIndex)
group_index
(Pattern -> Pattern)
-> CharParser (GroupIndex, GroupIndex) Pattern
-> CharParser (GroupIndex, GroupIndex) Pattern
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (Maybe GroupIndex -> Pattern -> Pattern
PGroup Maybe GroupIndex
index) (CharParser (GroupIndex, GroupIndex) Pattern
-> CharParser (GroupIndex, GroupIndex) Pattern)
-> CharParser (GroupIndex, GroupIndex) Pattern
-> CharParser (GroupIndex, GroupIndex) Pattern
forall a b. (a -> b) -> a -> b
$ ParsecT String (GroupIndex, GroupIndex) Identity Char
-> ParsecT String (GroupIndex, GroupIndex) Identity Char
-> CharParser (GroupIndex, GroupIndex) Pattern
-> CharParser (GroupIndex, GroupIndex) Pattern
forall s (m :: * -> *) t u open close a.
Stream s m t =>
ParsecT s u m open
-> ParsecT s u m close -> ParsecT s u m a -> ParsecT s u m a
between (Char -> ParsecT String (GroupIndex, GroupIndex) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'(') (Char -> ParsecT String (GroupIndex, GroupIndex) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
')') CharParser (GroupIndex, GroupIndex) Pattern
p_regex
p_post_atom :: Pattern -> ParsecT String u Identity Pattern
p_post_atom Pattern
atom = (Char -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'?' ParsecT String u Identity Char
-> ParsecT String u Identity Pattern
-> ParsecT String u Identity Pattern
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Pattern -> ParsecT String u Identity Pattern
forall (m :: * -> *) a. Monad m => a -> m a
return (Pattern -> Pattern
PQuest Pattern
atom))
ParsecT String u Identity Pattern
-> ParsecT String u Identity Pattern
-> ParsecT String u Identity Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Char -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'+' ParsecT String u Identity Char
-> ParsecT String u Identity Pattern
-> ParsecT String u Identity Pattern
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Pattern -> ParsecT String u Identity Pattern
forall (m :: * -> *) a. Monad m => a -> m a
return (Pattern -> Pattern
PPlus Pattern
atom))
ParsecT String u Identity Pattern
-> ParsecT String u Identity Pattern
-> ParsecT String u Identity Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Char -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'*' ParsecT String u Identity Char
-> ParsecT String u Identity Pattern
-> ParsecT String u Identity Pattern
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Pattern -> ParsecT String u Identity Pattern
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> Pattern -> Pattern
PStar Bool
True Pattern
atom))
ParsecT String u Identity Pattern
-> ParsecT String u Identity Pattern
-> ParsecT String u Identity Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Pattern -> ParsecT String u Identity Pattern
forall u. Pattern -> ParsecT String u Identity Pattern
p_bound Pattern
atom
ParsecT String u Identity Pattern
-> ParsecT String u Identity Pattern
-> ParsecT String u Identity Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Pattern -> ParsecT String u Identity Pattern
forall (m :: * -> *) a. Monad m => a -> m a
return Pattern
atom
p_bound :: Pattern -> GenParser Char st Pattern
p_bound Pattern
atom = GenParser Char st Pattern -> GenParser Char st Pattern
forall tok st a. GenParser tok st a -> GenParser tok st a
try (GenParser Char st Pattern -> GenParser Char st Pattern)
-> GenParser Char st Pattern -> GenParser Char st Pattern
forall a b. (a -> b) -> a -> b
$ ParsecT String st Identity Char
-> ParsecT String st Identity Char
-> GenParser Char st Pattern
-> GenParser Char st Pattern
forall s (m :: * -> *) t u open close a.
Stream s m t =>
ParsecT s u m open
-> ParsecT s u m close -> ParsecT s u m a -> ParsecT s u m a
between (Char -> ParsecT String st Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'{') (Char -> ParsecT String st Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'}') (Pattern -> GenParser Char st Pattern
forall u. Pattern -> ParsecT String u Identity Pattern
p_bound_spec Pattern
atom)
p_bound_spec :: Pattern -> ParsecT String u Identity Pattern
p_bound_spec Pattern
atom = do String
lowS <- ParsecT String u Identity Char -> ParsecT String u Identity String
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT String u Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
digit
let lowI :: GroupIndex
lowI = String -> GroupIndex
forall a. Read a => String -> a
read String
lowS
Maybe GroupIndex
highMI <- Maybe GroupIndex
-> ParsecT String u Identity (Maybe GroupIndex)
-> ParsecT String u Identity (Maybe GroupIndex)
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option (GroupIndex -> Maybe GroupIndex
forall a. a -> Maybe a
Just GroupIndex
lowI) (ParsecT String u Identity (Maybe GroupIndex)
-> ParsecT String u Identity (Maybe GroupIndex))
-> ParsecT String u Identity (Maybe GroupIndex)
-> ParsecT String u Identity (Maybe GroupIndex)
forall a b. (a -> b) -> a -> b
$ ParsecT String u Identity (Maybe GroupIndex)
-> ParsecT String u Identity (Maybe GroupIndex)
forall tok st a. GenParser tok st a -> GenParser tok st a
try (ParsecT String u Identity (Maybe GroupIndex)
-> ParsecT String u Identity (Maybe GroupIndex))
-> ParsecT String u Identity (Maybe GroupIndex)
-> ParsecT String u Identity (Maybe GroupIndex)
forall a b. (a -> b) -> a -> b
$ do
Char
_ <- Char -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
','
String
highS <- ParsecT String u Identity Char -> ParsecT String u Identity String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT String u Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
digit
if String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
highS then Maybe GroupIndex -> ParsecT String u Identity (Maybe GroupIndex)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe GroupIndex
forall a. Maybe a
Nothing
else do let highI :: GroupIndex
highI = String -> GroupIndex
forall a. Read a => String -> a
read String
highS
Bool -> ParsecT String u Identity ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (GroupIndex
lowI GroupIndex -> GroupIndex -> Bool
forall a. Ord a => a -> a -> Bool
<= GroupIndex
highI)
Maybe GroupIndex -> ParsecT String u Identity (Maybe GroupIndex)
forall (m :: * -> *) a. Monad m => a -> m a
return (GroupIndex -> Maybe GroupIndex
forall a. a -> Maybe a
Just (String -> GroupIndex
forall a. Read a => String -> a
read String
highS))
Pattern -> ParsecT String u Identity Pattern
forall (m :: * -> *) a. Monad m => a -> m a
return (GroupIndex -> Maybe GroupIndex -> Pattern -> Pattern
PBound GroupIndex
lowI Maybe GroupIndex
highMI Pattern
atom)
p_anchor :: CharParser (GroupIndex, GroupIndex) Pattern
p_anchor = (Char -> ParsecT String (GroupIndex, GroupIndex) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'^' ParsecT String (GroupIndex, GroupIndex) Identity Char
-> CharParser (GroupIndex, GroupIndex) Pattern
-> CharParser (GroupIndex, GroupIndex) Pattern
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (DoPa -> Pattern)
-> ParsecT String (GroupIndex, GroupIndex) Identity DoPa
-> CharParser (GroupIndex, GroupIndex) Pattern
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM DoPa -> Pattern
PCarat ParsecT String (GroupIndex, GroupIndex) Identity DoPa
forall s a. ParsecT s (a, GroupIndex) Identity DoPa
char_index)
CharParser (GroupIndex, GroupIndex) Pattern
-> CharParser (GroupIndex, GroupIndex) Pattern
-> CharParser (GroupIndex, GroupIndex) Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Char -> ParsecT String (GroupIndex, GroupIndex) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'$' ParsecT String (GroupIndex, GroupIndex) Identity Char
-> CharParser (GroupIndex, GroupIndex) Pattern
-> CharParser (GroupIndex, GroupIndex) Pattern
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (DoPa -> Pattern)
-> ParsecT String (GroupIndex, GroupIndex) Identity DoPa
-> CharParser (GroupIndex, GroupIndex) Pattern
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM DoPa -> Pattern
PDollar ParsecT String (GroupIndex, GroupIndex) Identity DoPa
forall s a. ParsecT s (a, GroupIndex) Identity DoPa
char_index)
CharParser (GroupIndex, GroupIndex) Pattern
-> CharParser (GroupIndex, GroupIndex) Pattern
-> CharParser (GroupIndex, GroupIndex) Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> CharParser (GroupIndex, GroupIndex) Pattern
-> CharParser (GroupIndex, GroupIndex) Pattern
forall tok st a. GenParser tok st a -> GenParser tok st a
try (do String
_ <- String -> ParsecT String (GroupIndex, GroupIndex) Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
"()"
Maybe GroupIndex
index <- CharParser (GroupIndex, GroupIndex) (Maybe GroupIndex)
group_index
Pattern -> CharParser (GroupIndex, GroupIndex) Pattern
forall (m :: * -> *) a. Monad m => a -> m a
return (Pattern -> CharParser (GroupIndex, GroupIndex) Pattern)
-> Pattern -> CharParser (GroupIndex, GroupIndex) Pattern
forall a b. (a -> b) -> a -> b
$ Maybe GroupIndex -> Pattern -> Pattern
PGroup Maybe GroupIndex
index Pattern
PEmpty)
CharParser (GroupIndex, GroupIndex) Pattern
-> String -> CharParser (GroupIndex, GroupIndex) Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"empty () or anchor ^ or $"
char_index :: ParsecT s (a, GroupIndex) Identity DoPa
char_index = do (a
gi,GroupIndex
ci) <- ParsecT s (a, GroupIndex) Identity (a, GroupIndex)
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
let ci' :: GroupIndex
ci' = GroupIndex -> GroupIndex
forall a. Enum a => a -> a
succ GroupIndex
ci
(a, GroupIndex) -> ParsecT s (a, GroupIndex) Identity ()
forall (m :: * -> *) u s. Monad m => u -> ParsecT s u m ()
setState (a
gi,GroupIndex
ci')
DoPa -> ParsecT s (a, GroupIndex) Identity DoPa
forall (m :: * -> *) a. Monad m => a -> m a
return (GroupIndex -> DoPa
DoPa GroupIndex
ci')
p_char :: ParsecT String (a, GroupIndex) Identity Pattern
p_char = ParsecT String (a, GroupIndex) Identity Pattern
forall a. ParsecT String (a, GroupIndex) Identity Pattern
p_dot ParsecT String (a, GroupIndex) Identity Pattern
-> ParsecT String (a, GroupIndex) Identity Pattern
-> ParsecT String (a, GroupIndex) Identity Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String (a, GroupIndex) Identity Pattern
forall a. ParsecT String (a, GroupIndex) Identity Pattern
p_left_brace ParsecT String (a, GroupIndex) Identity Pattern
-> ParsecT String (a, GroupIndex) Identity Pattern
-> ParsecT String (a, GroupIndex) Identity Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String (a, GroupIndex) Identity Pattern
forall a. ParsecT String (a, GroupIndex) Identity Pattern
p_escaped ParsecT String (a, GroupIndex) Identity Pattern
-> ParsecT String (a, GroupIndex) Identity Pattern
-> ParsecT String (a, GroupIndex) Identity Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String (a, GroupIndex) Identity Pattern
forall a. ParsecT String (a, GroupIndex) Identity Pattern
p_other_char where
p_dot :: ParsecT String (a, GroupIndex) Identity Pattern
p_dot = Char -> ParsecT String (a, GroupIndex) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'.' ParsecT String (a, GroupIndex) Identity Char
-> ParsecT String (a, GroupIndex) Identity DoPa
-> ParsecT String (a, GroupIndex) Identity DoPa
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String (a, GroupIndex) Identity DoPa
forall s a. ParsecT s (a, GroupIndex) Identity DoPa
char_index ParsecT String (a, GroupIndex) Identity DoPa
-> (DoPa -> ParsecT String (a, GroupIndex) Identity Pattern)
-> ParsecT String (a, GroupIndex) Identity Pattern
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Pattern -> ParsecT String (a, GroupIndex) Identity Pattern
forall (m :: * -> *) a. Monad m => a -> m a
return (Pattern -> ParsecT String (a, GroupIndex) Identity Pattern)
-> (DoPa -> Pattern)
-> DoPa
-> ParsecT String (a, GroupIndex) Identity Pattern
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DoPa -> Pattern
PDot
p_left_brace :: GenParser Char (a, GroupIndex) Pattern
p_left_brace = GenParser Char (a, GroupIndex) Pattern
-> GenParser Char (a, GroupIndex) Pattern
forall tok st a. GenParser tok st a -> GenParser tok st a
try (GenParser Char (a, GroupIndex) Pattern
-> GenParser Char (a, GroupIndex) Pattern)
-> GenParser Char (a, GroupIndex) Pattern
-> GenParser Char (a, GroupIndex) Pattern
forall a b. (a -> b) -> a -> b
$ (Char -> ParsecT String (a, GroupIndex) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'{' ParsecT String (a, GroupIndex) Identity Char
-> ParsecT String (a, GroupIndex) Identity ()
-> ParsecT String (a, GroupIndex) Identity ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String (a, GroupIndex) Identity Char
-> ParsecT String (a, GroupIndex) Identity ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT String (a, GroupIndex) Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
digit ParsecT String (a, GroupIndex) Identity ()
-> ParsecT String (a, GroupIndex) Identity DoPa
-> ParsecT String (a, GroupIndex) Identity DoPa
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String (a, GroupIndex) Identity DoPa
forall s a. ParsecT s (a, GroupIndex) Identity DoPa
char_index ParsecT String (a, GroupIndex) Identity DoPa
-> (DoPa -> GenParser Char (a, GroupIndex) Pattern)
-> GenParser Char (a, GroupIndex) Pattern
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Pattern -> GenParser Char (a, GroupIndex) Pattern
forall (m :: * -> *) a. Monad m => a -> m a
return (Pattern -> GenParser Char (a, GroupIndex) Pattern)
-> (DoPa -> Pattern)
-> DoPa
-> GenParser Char (a, GroupIndex) Pattern
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (DoPa -> Char -> Pattern
`PChar` Char
'{'))
p_escaped :: ParsecT String (a, GroupIndex) Identity Pattern
p_escaped = Char -> ParsecT String (a, GroupIndex) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'\\' ParsecT String (a, GroupIndex) Identity Char
-> ParsecT String (a, GroupIndex) Identity Char
-> ParsecT String (a, GroupIndex) Identity Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String (a, GroupIndex) Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar ParsecT String (a, GroupIndex) Identity Char
-> (Char -> ParsecT String (a, GroupIndex) Identity Pattern)
-> ParsecT String (a, GroupIndex) Identity Pattern
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Char
c -> ParsecT String (a, GroupIndex) Identity DoPa
forall s a. ParsecT s (a, GroupIndex) Identity DoPa
char_index ParsecT String (a, GroupIndex) Identity DoPa
-> (DoPa -> ParsecT String (a, GroupIndex) Identity Pattern)
-> ParsecT String (a, GroupIndex) Identity Pattern
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Pattern -> ParsecT String (a, GroupIndex) Identity Pattern
forall (m :: * -> *) a. Monad m => a -> m a
return (Pattern -> ParsecT String (a, GroupIndex) Identity Pattern)
-> (DoPa -> Pattern)
-> DoPa
-> ParsecT String (a, GroupIndex) Identity Pattern
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (DoPa -> Char -> Pattern
`PEscape` Char
c)
p_other_char :: ParsecT String (a, GroupIndex) Identity Pattern
p_other_char = String -> ParsecT String (a, GroupIndex) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
noneOf String
specials ParsecT String (a, GroupIndex) Identity Char
-> (Char -> ParsecT String (a, GroupIndex) Identity Pattern)
-> ParsecT String (a, GroupIndex) Identity Pattern
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Char
c -> ParsecT String (a, GroupIndex) Identity DoPa
forall s a. ParsecT s (a, GroupIndex) Identity DoPa
char_index ParsecT String (a, GroupIndex) Identity DoPa
-> (DoPa -> ParsecT String (a, GroupIndex) Identity Pattern)
-> ParsecT String (a, GroupIndex) Identity Pattern
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Pattern -> ParsecT String (a, GroupIndex) Identity Pattern
forall (m :: * -> *) a. Monad m => a -> m a
return (Pattern -> ParsecT String (a, GroupIndex) Identity Pattern)
-> (DoPa -> Pattern)
-> DoPa
-> ParsecT String (a, GroupIndex) Identity Pattern
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (DoPa -> Char -> Pattern
`PChar` Char
c)
where specials :: String
specials = String
"^.[$()|*+?{\\"
p_bracket :: ParsecT String (a, GroupIndex) Identity Pattern
p_bracket = (Char -> ParsecT String (a, GroupIndex) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'[') ParsecT String (a, GroupIndex) Identity Char
-> ParsecT String (a, GroupIndex) Identity Pattern
-> ParsecT String (a, GroupIndex) Identity Pattern
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ( (Char -> ParsecT String (a, GroupIndex) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'^' ParsecT String (a, GroupIndex) Identity Char
-> ParsecT String (a, GroupIndex) Identity Pattern
-> ParsecT String (a, GroupIndex) Identity Pattern
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> ParsecT String (a, GroupIndex) Identity Pattern
forall a. Bool -> ParsecT String (a, GroupIndex) Identity Pattern
p_set Bool
True) ParsecT String (a, GroupIndex) Identity Pattern
-> ParsecT String (a, GroupIndex) Identity Pattern
-> ParsecT String (a, GroupIndex) Identity Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Bool -> ParsecT String (a, GroupIndex) Identity Pattern
forall a. Bool -> ParsecT String (a, GroupIndex) Identity Pattern
p_set Bool
False) )
p_set :: Bool -> ParsecT String (a, GroupIndex) Identity Pattern
p_set Bool
invert = do String
initial <- (String
-> ParsecT String (a, GroupIndex) Identity String
-> ParsecT String (a, GroupIndex) Identity String
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option String
"" ((Char -> ParsecT String (a, GroupIndex) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
']' ParsecT String (a, GroupIndex) Identity Char
-> ParsecT String (a, GroupIndex) Identity String
-> ParsecT String (a, GroupIndex) Identity String
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> ParsecT String (a, GroupIndex) Identity String
forall (m :: * -> *) a. Monad m => a -> m a
return String
"]") ParsecT String (a, GroupIndex) Identity String
-> ParsecT String (a, GroupIndex) Identity String
-> ParsecT String (a, GroupIndex) Identity String
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Char -> ParsecT String (a, GroupIndex) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'-' ParsecT String (a, GroupIndex) Identity Char
-> ParsecT String (a, GroupIndex) Identity String
-> ParsecT String (a, GroupIndex) Identity String
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> ParsecT String (a, GroupIndex) Identity String
forall (m :: * -> *) a. Monad m => a -> m a
return String
"-")))
[BracketElement]
values <- if String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
initial then ParsecT String (a, GroupIndex) Identity BracketElement
-> ParsecT String (a, GroupIndex) Identity [BracketElement]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT String (a, GroupIndex) Identity BracketElement
forall u. ParsecT String u Identity BracketElement
p_set_elem else ParsecT String (a, GroupIndex) Identity BracketElement
-> ParsecT String (a, GroupIndex) Identity [BracketElement]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT String (a, GroupIndex) Identity BracketElement
forall u. ParsecT String u Identity BracketElement
p_set_elem
Char
_ <- Char -> ParsecT String (a, GroupIndex) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
']'
DoPa
ci <- ParsecT String (a, GroupIndex) Identity DoPa
forall s a. ParsecT s (a, GroupIndex) Identity DoPa
char_index
let chars :: Maybe (Set Char)
chars = String -> Maybe (Set Char)
forall a. Ord a => [a] -> Maybe (Set a)
maybe'set (String -> Maybe (Set Char)) -> String -> Maybe (Set Char)
forall a b. (a -> b) -> a -> b
$ String
initial
String -> String -> String
forall a. [a] -> [a] -> [a]
++ [Char
c | BEChar Char
c <- [BracketElement]
values ]
String -> String -> String
forall a. [a] -> [a] -> [a]
++ [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [String
s | BEChars String
s <- [BracketElement]
values ]
colls :: Maybe (Set PatternSetCollatingElement)
colls = [PatternSetCollatingElement]
-> Maybe (Set PatternSetCollatingElement)
forall a. Ord a => [a] -> Maybe (Set a)
maybe'set [String -> PatternSetCollatingElement
PatternSetCollatingElement String
coll | BEColl String
coll <- [BracketElement]
values ]
equivs :: Maybe (Set PatternSetEquivalenceClass)
equivs = [PatternSetEquivalenceClass]
-> Maybe (Set PatternSetEquivalenceClass)
forall a. Ord a => [a] -> Maybe (Set a)
maybe'set [String -> PatternSetEquivalenceClass
PatternSetEquivalenceClass String
equiv | BEEquiv String
equiv <- [BracketElement]
values]
class's :: Maybe (Set PatternSetCharacterClass)
class's = [PatternSetCharacterClass] -> Maybe (Set PatternSetCharacterClass)
forall a. Ord a => [a] -> Maybe (Set a)
maybe'set [String -> PatternSetCharacterClass
PatternSetCharacterClass String
a'class | BEClass String
a'class <- [BracketElement]
values]
maybe'set :: [a] -> Maybe (Set a)
maybe'set [a]
x = if [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [a]
x then Maybe (Set a)
forall a. Maybe a
Nothing else Set a -> Maybe (Set a)
forall a. a -> Maybe a
Just ([a] -> Set a
forall a. Ord a => [a] -> Set a
Set.fromList [a]
x)
sets :: PatternSet
sets = Maybe (Set Char)
-> Maybe (Set PatternSetCharacterClass)
-> Maybe (Set PatternSetCollatingElement)
-> Maybe (Set PatternSetEquivalenceClass)
-> PatternSet
PatternSet Maybe (Set Char)
chars Maybe (Set PatternSetCharacterClass)
class's Maybe (Set PatternSetCollatingElement)
colls Maybe (Set PatternSetEquivalenceClass)
equivs
PatternSet
sets PatternSet
-> ParsecT String (a, GroupIndex) Identity Pattern
-> ParsecT String (a, GroupIndex) Identity Pattern
`seq` Pattern -> ParsecT String (a, GroupIndex) Identity Pattern
forall (m :: * -> *) a. Monad m => a -> m a
return (Pattern -> ParsecT String (a, GroupIndex) Identity Pattern)
-> Pattern -> ParsecT String (a, GroupIndex) Identity Pattern
forall a b. (a -> b) -> a -> b
$ if Bool
invert then DoPa -> PatternSet -> Pattern
PAnyNot DoPa
ci PatternSet
sets else DoPa -> PatternSet -> Pattern
PAny DoPa
ci PatternSet
sets
p_set_elem :: ParsecT String u Identity BracketElement
p_set_elem = ParsecT String u Identity BracketElement
forall u. ParsecT String u Identity BracketElement
p_set_elem_class ParsecT String u Identity BracketElement
-> ParsecT String u Identity BracketElement
-> ParsecT String u Identity BracketElement
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String u Identity BracketElement
forall u. ParsecT String u Identity BracketElement
p_set_elem_equiv ParsecT String u Identity BracketElement
-> ParsecT String u Identity BracketElement
-> ParsecT String u Identity BracketElement
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String u Identity BracketElement
forall u. ParsecT String u Identity BracketElement
p_set_elem_coll
ParsecT String u Identity BracketElement
-> ParsecT String u Identity BracketElement
-> ParsecT String u Identity BracketElement
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String u Identity BracketElement
forall u. ParsecT String u Identity BracketElement
p_set_elem_range ParsecT String u Identity BracketElement
-> ParsecT String u Identity BracketElement
-> ParsecT String u Identity BracketElement
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String u Identity BracketElement
forall u. ParsecT String u Identity BracketElement
p_set_elem_char ParsecT String u Identity BracketElement
-> String -> ParsecT String u Identity BracketElement
forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"Failed to parse bracketed string"
p_set_elem_class :: ParsecT String st Identity BracketElement
p_set_elem_class = (String -> BracketElement)
-> ParsecT String st Identity String
-> ParsecT String st Identity BracketElement
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM String -> BracketElement
BEClass (ParsecT String st Identity String
-> ParsecT String st Identity BracketElement)
-> ParsecT String st Identity String
-> ParsecT String st Identity BracketElement
forall a b. (a -> b) -> a -> b
$
ParsecT String st Identity String
-> ParsecT String st Identity String
forall tok st a. GenParser tok st a -> GenParser tok st a
try (ParsecT String st Identity String
-> ParsecT String st Identity String
-> ParsecT String st Identity String
-> ParsecT String st Identity String
forall s (m :: * -> *) t u open close a.
Stream s m t =>
ParsecT s u m open
-> ParsecT s u m close -> ParsecT s u m a -> ParsecT s u m a
between (String -> ParsecT String st Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
"[:") (String -> ParsecT String st Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
":]") (ParsecT String st Identity Char
-> ParsecT String st Identity String
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (ParsecT String st Identity Char
-> ParsecT String st Identity String)
-> ParsecT String st Identity Char
-> ParsecT String st Identity String
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String st Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
noneOf String
":]"))
p_set_elem_equiv :: ParsecT String st Identity BracketElement
p_set_elem_equiv = (String -> BracketElement)
-> ParsecT String st Identity String
-> ParsecT String st Identity BracketElement
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM String -> BracketElement
BEEquiv (ParsecT String st Identity String
-> ParsecT String st Identity BracketElement)
-> ParsecT String st Identity String
-> ParsecT String st Identity BracketElement
forall a b. (a -> b) -> a -> b
$
ParsecT String st Identity String
-> ParsecT String st Identity String
forall tok st a. GenParser tok st a -> GenParser tok st a
try (ParsecT String st Identity String
-> ParsecT String st Identity String
-> ParsecT String st Identity String
-> ParsecT String st Identity String
forall s (m :: * -> *) t u open close a.
Stream s m t =>
ParsecT s u m open
-> ParsecT s u m close -> ParsecT s u m a -> ParsecT s u m a
between (String -> ParsecT String st Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
"[=") (String -> ParsecT String st Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
"=]") (ParsecT String st Identity Char
-> ParsecT String st Identity String
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (ParsecT String st Identity Char
-> ParsecT String st Identity String)
-> ParsecT String st Identity Char
-> ParsecT String st Identity String
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String st Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
noneOf String
"=]"))
p_set_elem_coll :: ParsecT String st Identity BracketElement
p_set_elem_coll = (String -> BracketElement)
-> ParsecT String st Identity String
-> ParsecT String st Identity BracketElement
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM String -> BracketElement
BEColl (ParsecT String st Identity String
-> ParsecT String st Identity BracketElement)
-> ParsecT String st Identity String
-> ParsecT String st Identity BracketElement
forall a b. (a -> b) -> a -> b
$
ParsecT String st Identity String
-> ParsecT String st Identity String
forall tok st a. GenParser tok st a -> GenParser tok st a
try (ParsecT String st Identity String
-> ParsecT String st Identity String
-> ParsecT String st Identity String
-> ParsecT String st Identity String
forall s (m :: * -> *) t u open close a.
Stream s m t =>
ParsecT s u m open
-> ParsecT s u m close -> ParsecT s u m a -> ParsecT s u m a
between (String -> ParsecT String st Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
"[.") (String -> ParsecT String st Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
".]") (ParsecT String st Identity Char
-> ParsecT String st Identity String
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (ParsecT String st Identity Char
-> ParsecT String st Identity String)
-> ParsecT String st Identity Char
-> ParsecT String st Identity String
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String st Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
noneOf String
".]"))
p_set_elem_range :: GenParser Char st BracketElement
p_set_elem_range = GenParser Char st BracketElement
-> GenParser Char st BracketElement
forall tok st a. GenParser tok st a -> GenParser tok st a
try (GenParser Char st BracketElement
-> GenParser Char st BracketElement)
-> GenParser Char st BracketElement
-> GenParser Char st BracketElement
forall a b. (a -> b) -> a -> b
$ do
Char
start <- String -> ParsecT String st Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
noneOf String
"]-"
Char
_ <- Char -> ParsecT String st Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'-'
Char
end <- String -> ParsecT String st Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
noneOf String
"]"
if Char
start Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
end
then BracketElement -> GenParser Char st BracketElement
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> BracketElement
BEChars [Char
start..Char
end])
else String -> GenParser Char st BracketElement
forall s (m :: * -> *) t u a.
Stream s m t =>
String -> ParsecT s u m a
unexpected String
"End point of dashed character range is less than starting point"
p_set_elem_char :: ParsecT String u Identity BracketElement
p_set_elem_char = do
Char
c <- String -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
noneOf String
"]"
Bool
-> ParsecT String u Identity () -> ParsecT String u Identity ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'-') (ParsecT String u Identity () -> ParsecT String u Identity ())
-> ParsecT String u Identity () -> ParsecT String u Identity ()
forall a b. (a -> b) -> a -> b
$ do
Bool
atEnd <- (ParsecT String u Identity Char -> ParsecT String u Identity Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (Char -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
']') ParsecT String u Identity Char
-> ParsecT String u Identity Bool -> ParsecT String u Identity Bool
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> ParsecT String u Identity Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True) ParsecT String u Identity Bool
-> ParsecT String u Identity Bool -> ParsecT String u Identity Bool
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Bool -> ParsecT String u Identity Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False)
Bool
-> ParsecT String u Identity () -> ParsecT String u Identity ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool -> Bool
not Bool
atEnd) (String -> ParsecT String u Identity ()
forall s (m :: * -> *) t u a.
Stream s m t =>
String -> ParsecT s u m a
unexpected String
"A dash is in the wrong place in a bracket")
BracketElement -> ParsecT String u Identity BracketElement
forall (m :: * -> *) a. Monad m => a -> m a
return (Char -> BracketElement
BEChar Char
c)