skylighting-0.3.3.1: syntax highlighting library

Safe Haskell | None
Language | Haskell2010

Skylighting.Regex

Synopsis

- data Regex :: *
- data RegexException
- data RE = RE {
  - reString :: ByteString
  - reCaseSensitive :: Bool
  }
- compileRegex :: Bool -> ByteString -> Regex
- matchRegex :: Regex -> ByteString -> Maybe [ByteString]
- convertOctalEscapes :: String -> String

# Documentation

data Regex :: * #

A compiled regular expression

Instances

RegexOptions Regex CompOption ExecOption |
Methods blankCompOpt :: CompOption blankExecOpt :: ExecOption defaultCompOpt :: CompOption defaultExecOpt :: ExecOption setExecOpts :: ExecOption -> Regex -> Regex getExecOpts :: Regex -> ExecOption

data RegexException Source #

An exception in compiling or executing a regex.

Instances

Show RegexException Source # |
Methods showsPrec :: Int -> RegexException -> ShowS # show :: RegexException -> String # showList :: [RegexException] -> ShowS #
Generic RegexException Source # |
Associated Types type Rep RegexException :: * -> * # Methods from :: RegexException -> Rep RegexException x # to :: Rep RegexException x -> RegexException #
Exception RegexException Source # |
Methods toException :: RegexException -> SomeException # fromException :: SomeException -> Maybe RegexException # displayException :: RegexException -> String #
type Rep RegexException Source # |
type Rep RegexException = D1 (MetaData "RegexException" "Skylighting.Regex" "skylighting-0.3.3.1-AsHtinoWKN3LkTvrtcdLM" True) (C1 (MetaCons "RegexException" PrefixI False) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 String)))

data RE Source #

A representation of a regular expression.

Constructors

RE |

Fields

- reString :: ByteString
- reCaseSensitive :: Bool

Instances

Eq RE Source # |
Methods (==) :: RE -> RE -> Bool # (/=) :: RE -> RE -> Bool #
Data RE Source # |

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> RE -> c RE #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c RE #

toConstr :: RE -> Constr #

dataTypeOf :: RE -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c RE) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c RE) #

gmapT :: (forall b. Data b => b -> b) -> RE -> RE #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> RE -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> RE -> r #

gmapQ :: (forall d. Data d => d -> u) -> RE -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> RE -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> RE -> m RE #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> RE -> m RE #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> RE -> m RE #

Ord RE Source # |
Methods compare :: RE -> RE -> Ordering # (<) :: RE -> RE -> Bool # (<=) :: RE -> RE -> Bool # (>) :: RE -> RE -> Bool # (>=) :: RE -> RE -> Bool # max :: RE -> RE -> RE # min :: RE -> RE -> RE #
Read RE Source # |
Methods readsPrec :: Int -> ReadS RE # readList :: ReadS [RE] # readPrec :: ReadPrec RE # readListPrec :: ReadPrec [RE] #
Show RE Source # |
Methods showsPrec :: Int -> RE -> ShowS # show :: RE -> String # showList :: [RE] -> ShowS #
Generic RE Source # |
Associated Types type Rep RE :: * -> * # Methods from :: RE -> Rep RE x # to :: Rep RE x -> RE #
Binary RE Source # |
Methods put :: RE -> Put # get :: Get RE # putList :: [RE] -> Put #
type Rep RE Source # |
type Rep RE = D1 (MetaData "RE" "Skylighting.Regex" "skylighting-0.3.3.1-AsHtinoWKN3LkTvrtcdLM" False) (C1 (MetaCons "RE" PrefixI True) ((:*:) (S1 (MetaSel (Just Symbol "reString") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 ByteString)) (S1 (MetaSel (Just Symbol "reCaseSensitive") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Bool))))

compileRegex :: Bool -> ByteString -> Regex Source #

Compile a PCRE regex. If the first parameter is True, the regex is case-sensitive, otherwise caseless. The regex is compiled from a bytestring interpreted as UTF-8. If the regex cannot be compiled, a `RegexException` is thrown.

matchRegex :: Regex -> ByteString -> Maybe [ByteString] Source #

Match a `Regex` against a bytestring. Returns `Nothing` if no match, otherwise `Just` a nonempty list of bytestrings. The first bytestring in the list is the match, the others the captures, if any. If there are errors in executing the regex, a `RegexException` is thrown.

convertOctalEscapes :: String -> String Source #

Convert octal escapes to the form pcre wants. Note: need at least pcre 8.34 for the form o{dddd}. So we prefer ddd or x{...}.