{- This module was generated from data in the Kate syntax highlighting file doxygen.xml, version 1.31,
   by  Dominik Haumann (dhdev@gmx.de) -}

module Text.Highlighting.Kate.Syntax.Doxygen ( highlight, parseExpression, syntaxName, syntaxExtensions ) where
import Text.Highlighting.Kate.Definitions
import Text.Highlighting.Kate.Common
import qualified Text.Highlighting.Kate.Syntax.Alert
import Text.ParserCombinators.Parsec
import Control.Monad (when)
import Data.Map (fromList)
import Data.Maybe (fromMaybe, maybeToList)

import qualified Data.Set as Set
-- | Full name of language.
syntaxName :: String
syntaxName = "Doxygen"

-- | Filename extensions for this language.
syntaxExtensions :: String
syntaxExtensions = "*.dox;*.doxygen"

-- | Highlight source code using this syntax definition.
highlight :: String -> Either String [SourceLine]
highlight input =
  case runParser parseSource startingState "source" input of
    Left err     -> Left $ show err
    Right result -> Right result

-- | Parse an expression using appropriate local context.
parseExpression :: GenParser Char SyntaxState LabeledSource
parseExpression = do
  st <- getState
  let oldLang = synStLanguage st
  setState $ st { synStLanguage = "Doxygen" }
  context <- currentContext <|> (pushContext "Normal" >> currentContext)
  result <- parseRules context
  updateState $ \st -> st { synStLanguage = oldLang }
  return result

parseSource = do 
  lineContents <- lookAhead wholeLine
  updateState $ \st -> st { synStCurrentLine = lineContents }
  result <- manyTill parseSourceLine eof
  return $ map normalizeHighlighting result

startingState = SyntaxState {synStContexts = fromList [("Doxygen",["Normal"])], synStLanguage = "Doxygen", synStCurrentLine = "", synStCharsParsedInLine = 0, synStPrevChar = '\n', synStCaseSensitive = True, synStKeywordCaseSensitive = False, synStCaptures = []}

parseSourceLine = manyTill parseExpressionInternal pEndLine

pEndLine = do
  lookAhead $ newline <|> (eof >> return '\n')
  context <- currentContext
  case context of
    "Normal" -> return () >> pHandleEndLine
    "LineComment" -> (popContext) >> pEndLine
    "BlockComment" -> return () >> pHandleEndLine
    "ML_TagWord" -> (popContext) >> pEndLine
    "ML_TagParam" -> (popContext) >> pEndLine
    "ML_TagWordWord" -> (popContext) >> pEndLine
    "ML_Tag2ndWord" -> (popContext >> popContext) >> pEndLine
    "ML_TagString" -> (popContext) >> pEndLine
    "ML_TagWordString" -> (popContext) >> pEndLine
    "ML_htmltag" -> return () >> pHandleEndLine
    "ML_htmlcomment" -> return () >> pHandleEndLine
    "ML_identifiers" -> return () >> pHandleEndLine
    "ML_types1" -> return () >> pHandleEndLine
    "ML_types2" -> return () >> pHandleEndLine
    "SL_TagWord" -> (popContext) >> pEndLine
    "SL_TagParam" -> (popContext) >> pEndLine
    "SL_TagWordWord" -> (popContext) >> pEndLine
    "SL_Tag2ndWord" -> (popContext >> popContext) >> pEndLine
    "SL_TagString" -> (popContext) >> pEndLine
    "SL_TagWordString" -> (popContext) >> pEndLine
    "SL_htmltag" -> (popContext) >> pEndLine
    "SL_htmlcomment" -> (popContext) >> pEndLine
    "SL_identifiers" -> (popContext) >> pEndLine
    "SL_types1" -> (popContext) >> pEndLine
    "SL_types2" -> (popContext) >> pEndLine
    "SL_DetectEnv" -> (popContext) >> pEndLine
    "SL_DetectComment" -> (popContext) >> pEndLine
    "Code" -> return () >> pHandleEndLine
    "Verbatim" -> return () >> pHandleEndLine
    "Formula" -> return () >> pHandleEndLine
    "Msc" -> return () >> pHandleEndLine
    "Dot" -> return () >> pHandleEndLine
    _ -> pHandleEndLine

withAttribute attr txt = do
  when (null txt) $ fail "Parser matched no text"
  let labs = attr : maybeToList (lookup attr styles)
  st <- getState
  let oldCharsParsed = synStCharsParsedInLine st
  let prevchar = if null txt then '\n' else last txt
  updateState $ \st -> st { synStCharsParsedInLine = oldCharsParsed + length txt, synStPrevChar = prevchar } 
  return (labs, txt)

styles = [("Tags","kw"),("Word","kw"),("HTML Tag","kw"),("Description","st"),("Comment","co"),("Region","re"),("Identifier","ot"),("HTML Comment","co"),("Types","dt"),("Code","co"),("Dot Graph","co"),("Formulas","co"),("Message Sequence Chart","co"),("Verbatim","co")]

parseExpressionInternal = do
  context <- currentContext
  parseRules context <|> (pDefault >>= withAttribute (fromMaybe "" $ lookup context defaultAttributes))

list_TagOnly = Set.fromList $ words $ "\\arg \\attention \\author \\callgraph \\callergraph \\details \\dot \\else \\endcond \\enddot \\endhtmlonly \\endif \\endlatexonly \\endlink \\endmanonly \\endmsc \\endverbatim \\endxmlonly \\f[ \\f] \\f$ \\hideinitializer \\htmlonly \\interface \\internal \\invariant \\~ \\@ \\$ \\\\ \\# \\latexonly \\li \\manonly \\msc \\n \\nosubgrouping \\note \\only \\post \\pre \\private \\privatesection \\protected \\protectedsection \\public \\publicsection \\remarks \\return \\returns \\showinitializer \\since \\test \\todo \\verbatim \\warning \\xmlonly @arg @attention @author @callgraph @callergraph @details @dot @else @endcond @enddot @endhtmlonly @endif @endlatexonly @endlink @endmanonly @endmsc @endverbatim @endxmlonly @f[ @f] @f$ @hideinitializer @htmlonly @interface @internal @invariant @~ @@ @$ @\\ @# @latexonly @li @manonly @msc @n @nosubgrouping @note @only @post @pre @pivate @pivatesection @protected @protectedsection @public @publicsection @remarks @return @returns @showinitializer @since @test @todo @verbatim @warning @xmlonly"
list_TagWord = Set.fromList $ words $ "\\addtogroup \\a \\anchor \\b \\c \\class \\cond \\copybrief \\copydetails \\copydoc \\def \\dir \\dontinclude \\dotfile \\e \\elseif \\em \\enum \\example \\exception \\exceptions \\extends \\file \\htmlinclude \\if \\ifnot \\implements \\include \\includelineno \\link \\memberof \\namespace \\p \\package \\property \\protocol \\ref \\relatesalso \\relates \\retval \\throw \\throws \\verbinclude \\version \\xrefitem @addtogroup @a @anchor @b @c @class @cond @copybrief @copydetails @copydoc @def @dir @dontinclude @dotfile @e @elseif @em @enum @example @exception @exceptions @extends @file @htmlinclude @if @ifnot @implements @include @includelineno @link @memberof @namespace @p @package @property @prtocol @ref @relatesalso @relates @retval @throw @throws @verbinclude @version @xrefitem"
list_TagParam = Set.fromList $ words $ "\\param \\tparam @param @tparam"
list_TagWordWord = Set.fromList $ words $ "\\image @image"
list_TagWordString = Set.fromList $ words $ "\\category \\defgroup \\headerfile \\page \\paragraph \\section \\struct \\subpage \\subsection \\subsubsection \\union \\weakgroup @category @defgroup @headerfile @page @paragraph @section @struct @subpage @subsection @subsubsection @union @weakgroup"
list_TagString = Set.fromList $ words $ "\\addindex \\brief \\bug \\date \\deprecated \\fn \\ingroup \\line \\mainpage \\name \\overload \\par \\sa \\see \\short \\skip \\skipline \\typedef \\until \\var @addindex @brief @bug @date @deprecated @fn @ingroup @line @mainpage @name @overload @par @sa @see @short @skip @skipline @typedef @until @var"

regex_'2f'2f'28'21'7c'28'2f'28'3f'3d'5b'5e'2f'5d'7c'24'29'29'29'3c'3f = compileRegex "//(!|(/(?=[^/]|$)))<?"
regex_'2f'5c'2a'28'5c'2a'5b'5e'2a'2f'5d'7c'21'7c'5b'2a'21'5d'3c'7c'5c'2a'24'29 = compileRegex "/\\*(\\*[^*/]|!|[*!]<|\\*$)"
regex_'2f'2f'5cs'2a'40'5c'7b'5cs'2a'24 = compileRegex "//\\s*@\\{\\s*$"
regex_'2f'2f'5cs'2a'40'5c'7d'5cs'2a'24 = compileRegex "//\\s*@\\}\\s*$"
regex_'2f'5c'2a'5cs'2a'40'5c'7b'5cs'2a'5c'2a'2f = compileRegex "/\\*\\s*@\\{\\s*\\*/"
regex_'2f'5c'2a'5cs'2a'40'5c'7d'5cs'2a'5c'2a'2f = compileRegex "/\\*\\s*@\\}\\s*\\*/"
regex_'3c'5c'2f'3f'5ba'2dzA'2dZ'5f'3a'5d'5ba'2dzA'2dZ0'2d9'2e'5f'3a'2d'5d'2a = compileRegex "<\\/?[a-zA-Z_:][a-zA-Z0-9._:-]*"
regex_'5c'5c'28'3c'7c'3e'29 = compileRegex "\\\\(<|>)"
regex_'5cS'28'3f'3d'28'5b'5d'5b'2c'3f'3b'28'29'5d'7c'5c'2e'24'7c'5c'2e'3f'5cs'29'29 = compileRegex "\\S(?=([][,?;()]|\\.$|\\.?\\s))"
regex_'5cS = compileRegex "\\S"
regex_'2e = compileRegex "."
regex_'5cs'2a'3d'5cs'2a = compileRegex "\\s*=\\s*"
regex_'5cs'2a'23'3f'5ba'2dzA'2dZ0'2d9'5d'2a = compileRegex "\\s*#?[a-zA-Z0-9]*"
regex_'5b'40'5c'5c'5dcode = compileRegex "[@\\\\]code"
regex_'5b'40'5c'5c'5dverbatim = compileRegex "[@\\\\]verbatim"
regex_'5b'40'5c'5c'5df'5c'5b = compileRegex "[@\\\\]f\\["
regex_'5b'40'5c'5c'5dmsc = compileRegex "[@\\\\]msc"
regex_'5b'40'5c'5c'5ddot = compileRegex "[@\\\\]dot"
regex_'5cs'2a'28'5c'2a'2f'29 = compileRegex "\\s*(\\*/)"
regex_'5cs'2a'28'5c'2a'7c'2f'2f'28'21'7c'28'2f'28'3f'3d'5b'5e'2f'5d'7c'24'29'29'29'3c'3f'29 = compileRegex "\\s*(\\*|//(!|(/(?=[^/]|$)))<?)"
regex_'5b'40'5c'5c'5dendcode = compileRegex "[@\\\\]endcode"
regex_'5b'40'5c'5c'5dendverbatim = compileRegex "[@\\\\]endverbatim"
regex_'5b'40'5c'5c'5df'5c'5d = compileRegex "[@\\\\]f\\]"
regex_'5b'40'5c'5c'5dendmsc = compileRegex "[@\\\\]endmsc"
regex_'5b'40'5c'5c'5denddot = compileRegex "[@\\\\]enddot"

defaultAttributes = [("Normal","Normal Text"),("LineComment","Comment"),("BlockComment","Comment"),("ML_TagWord","Comment"),("ML_TagParam","Comment"),("ML_TagWordWord","Comment"),("ML_Tag2ndWord","Comment"),("ML_TagString","Comment"),("ML_TagWordString","Comment"),("ML_htmltag","Identifier"),("ML_htmlcomment","HTML Comment"),("ML_identifiers","Identifier"),("ML_types1","Types"),("ML_types2","Types"),("SL_TagWord","Comment"),("SL_TagParam","Comment"),("SL_TagWordWord","Comment"),("SL_Tag2ndWord","Comment"),("SL_TagString","Comment"),("SL_TagWordString","Comment"),("SL_htmltag","Identifier"),("SL_htmlcomment","HTML Comment"),("SL_identifiers","Identifier"),("SL_types1","Types"),("SL_types2","Types"),("SL_DetectEnv",""),("SL_DetectComment",""),("Code","Code"),("Verbatim","Verbatim"),("Formula","Formulas"),("Msc","Message Sequence Chart"),("Dot","Dot Graph")]

parseRules "Normal" = 
  do (attr, result) <- (((pRegExpr regex_'2f'2f'28'21'7c'28'2f'28'3f'3d'5b'5e'2f'5d'7c'24'29'29'29'3c'3f >>= withAttribute "Comment") >>~ pushContext "LineComment")
                        <|>
                        ((pRegExpr regex_'2f'5c'2a'28'5c'2a'5b'5e'2a'2f'5d'7c'21'7c'5b'2a'21'5d'3c'7c'5c'2a'24'29 >>= withAttribute "Comment") >>~ pushContext "BlockComment")
                        <|>
                        ((pRegExpr regex_'2f'2f'5cs'2a'40'5c'7b'5cs'2a'24 >>= withAttribute "Region"))
                        <|>
                        ((pRegExpr regex_'2f'2f'5cs'2a'40'5c'7d'5cs'2a'24 >>= withAttribute "Region"))
                        <|>
                        ((pRegExpr regex_'2f'5c'2a'5cs'2a'40'5c'7b'5cs'2a'5c'2a'2f >>= withAttribute "Region"))
                        <|>
                        ((pRegExpr regex_'2f'5c'2a'5cs'2a'40'5c'7d'5cs'2a'5c'2a'2f >>= withAttribute "Region")))
     return (attr, result)

parseRules "LineComment" = 
  do (attr, result) <- (((pLineContinue >>= withAttribute "Comment"))
                        <|>
                        ((pDetectSpaces >>= withAttribute "Comment"))
                        <|>
                        ((Text.Highlighting.Kate.Syntax.Alert.parseExpression))
                        <|>
                        ((parseRules "SL_DetectEnv"))
                        <|>
                        ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}" list_TagOnly >>= withAttribute "Tags"))
                        <|>
                        ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}" list_TagWord >>= withAttribute "Tags") >>~ pushContext "SL_TagWord")
                        <|>
                        ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}" list_TagParam >>= withAttribute "Tags") >>~ pushContext "SL_TagParam")
                        <|>
                        ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}" list_TagWordWord >>= withAttribute "Tags") >>~ pushContext "SL_TagWordWord")
                        <|>
                        ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}" list_TagString >>= withAttribute "Tags") >>~ pushContext "SL_TagString")
                        <|>
                        ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}" list_TagWordString >>= withAttribute "Tags") >>~ pushContext "SL_TagWordString")
                        <|>
                        ((pDetectIdentifier >>= withAttribute "Comment"))
                        <|>
                        ((pString False "<!--" >>= withAttribute "HTML Comment") >>~ pushContext "SL_htmlcomment")
                        <|>
                        ((pDetect2Chars False '<' '<' >>= withAttribute "Comment"))
                        <|>
                        ((pRegExpr regex_'3c'5c'2f'3f'5ba'2dzA'2dZ'5f'3a'5d'5ba'2dzA'2dZ0'2d9'2e'5f'3a'2d'5d'2a >>= withAttribute "HTML Tag") >>~ pushContext "SL_htmltag"))
     return (attr, result)

parseRules "BlockComment" = 
  do (attr, result) <- (((pDetectSpaces >>= withAttribute "Comment"))
                        <|>
                        ((pDetect2Chars False '*' '/' >>= withAttribute "Comment") >>~ (popContext))
                        <|>
                        ((Text.Highlighting.Kate.Syntax.Alert.parseExpression))
                        <|>
                        ((pDetect2Chars False '@' '{' >>= withAttribute "Region"))
                        <|>
                        ((pDetect2Chars False '@' '}' >>= withAttribute "Region"))
                        <|>
                        ((parseRules "SL_DetectEnv"))
                        <|>
                        ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}" list_TagOnly >>= withAttribute "Tags"))
                        <|>
                        ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}" list_TagWord >>= withAttribute "Tags") >>~ pushContext "ML_TagWord")
                        <|>
                        ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}" list_TagParam >>= withAttribute "Tags") >>~ pushContext "ML_TagParam")
                        <|>
                        ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}" list_TagWordWord >>= withAttribute "Tags") >>~ pushContext "ML_TagWordWord")
                        <|>
                        ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}" list_TagString >>= withAttribute "Tags") >>~ pushContext "ML_TagString")
                        <|>
                        ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}" list_TagWordString >>= withAttribute "Tags") >>~ pushContext "ML_TagWordString")
                        <|>
                        ((pDetectIdentifier >>= withAttribute "Comment"))
                        <|>
                        ((pRegExpr regex_'5c'5c'28'3c'7c'3e'29 >>= withAttribute "Tags"))
                        <|>
                        ((pDetect2Chars False '<' '<' >>= withAttribute "Comment"))
                        <|>
                        ((pRegExpr regex_'3c'5c'2f'3f'5ba'2dzA'2dZ'5f'3a'5d'5ba'2dzA'2dZ0'2d9'2e'5f'3a'2d'5d'2a >>= withAttribute "HTML Tag") >>~ pushContext "ML_htmltag")
                        <|>
                        ((pString False "<!--" >>= withAttribute "HTML Comment") >>~ pushContext "ML_htmlcomment"))
     return (attr, result)

parseRules "ML_TagWord" = 
  do (attr, result) <- (((lookAhead (pDetect2Chars False '*' '/') >> return ([],"") ) >>~ (popContext))
                        <|>
                        ((parseRules "SL_TagWord")))
     return (attr, result)

parseRules "ML_TagParam" = 
  do (attr, result) <- (((lookAhead (pDetect2Chars False '*' '/') >> return ([],"") ) >>~ (popContext))
                        <|>
                        ((pDetectSpaces >>= withAttribute "Comment"))
                        <|>
                        ((pString False "[in]" >>= withAttribute "Tags") >>~ pushContext "ML_Tag2ndWord")
                        <|>
                        ((pString False "[out]" >>= withAttribute "Tags") >>~ pushContext "ML_Tag2ndWord")
                        <|>
                        ((pString False "[in,out]" >>= withAttribute "Tags") >>~ pushContext "ML_Tag2ndWord")
                        <|>
                        ((pRegExpr regex_'5cS'28'3f'3d'28'5b'5d'5b'2c'3f'3b'28'29'5d'7c'5c'2e'24'7c'5c'2e'3f'5cs'29'29 >>= withAttribute "Word") >>~ (popContext))
                        <|>
                        ((pRegExpr regex_'5cS >>= withAttribute "Word")))
     return (attr, result)

parseRules "ML_TagWordWord" = 
  do (attr, result) <- (((lookAhead (pDetect2Chars False '*' '/') >> return ([],"") ) >>~ (popContext))
                        <|>
                        ((pDetectSpaces >>= withAttribute "Comment"))
                        <|>
                        ((pRegExpr regex_'5cS'28'3f'3d'28'5b'5d'5b'2c'3f'3b'28'29'5d'7c'5c'2e'24'7c'5c'2e'3f'5cs'29'29 >>= withAttribute "Word") >>~ pushContext "ML_Tag2ndWord")
                        <|>
                        ((pRegExpr regex_'5cS >>= withAttribute "Word")))
     return (attr, result)

parseRules "ML_Tag2ndWord" = 
  do (attr, result) <- (((lookAhead (pDetect2Chars False '*' '/') >> return ([],"") ) >>~ (popContext >> popContext))
                        <|>
                        ((parseRules "SL_Tag2ndWord")))
     return (attr, result)

parseRules "ML_TagString" = 
  do (attr, result) <- (((pDetectSpaces >>= withAttribute "Comment"))
                        <|>
                        ((lookAhead (pDetect2Chars False '*' '/') >> return ([],"") ) >>~ (popContext))
                        <|>
                        ((pString False "<!--" >>= withAttribute "HTML Comment") >>~ pushContext "ML_htmlcomment")
                        <|>
                        ((pDetect2Chars False '<' '<' >>= withAttribute "Comment"))
                        <|>
                        ((pRegExpr regex_'3c'5c'2f'3f'5ba'2dzA'2dZ'5f'3a'5d'5ba'2dzA'2dZ0'2d9'2e'5f'3a'2d'5d'2a >>= withAttribute "HTML Tag") >>~ pushContext "ML_htmltag")
                        <|>
                        ((pRegExpr regex_'2e >>= withAttribute "Description")))
     return (attr, result)

parseRules "ML_TagWordString" = 
  do (attr, result) <- (((lookAhead (pDetect2Chars False '*' '/') >> return ([],"") ) >>~ (popContext))
                        <|>
                        ((parseRules "SL_TagWordString")))
     return (attr, result)

parseRules "ML_htmltag" = 
  do (attr, result) <- (((lookAhead (pDetect2Chars False '*' '/') >> return ([],"") ) >>~ (popContext))
                        <|>
                        ((pDetect2Chars False '/' '>' >>= withAttribute "HTML Tag") >>~ (popContext))
                        <|>
                        ((pDetectChar False '>' >>= withAttribute "HTML Tag") >>~ (popContext))
                        <|>
                        ((pRegExpr regex_'5cs'2a'3d'5cs'2a >>= withAttribute "Identifier") >>~ pushContext "ML_identifiers"))
     return (attr, result)

parseRules "ML_htmlcomment" = 
  do (attr, result) <- (((lookAhead (pDetect2Chars False '*' '/') >> return ([],"") ) >>~ (popContext))
                        <|>
                        ((Text.Highlighting.Kate.Syntax.Alert.parseExpression))
                        <|>
                        ((pString False "-->" >>= withAttribute "HTML Comment") >>~ (popContext)))
     return (attr, result)

parseRules "ML_identifiers" = 
  do (attr, result) <- (((lookAhead (pDetect2Chars False '*' '/') >> return ([],"") ) >>~ (popContext))
                        <|>
                        ((pRegExpr regex_'5cs'2a'23'3f'5ba'2dzA'2dZ0'2d9'5d'2a >>= withAttribute "String") >>~ (popContext))
                        <|>
                        ((pDetectChar False '\'' >>= withAttribute "Types") >>~ pushContext "ML_types1")
                        <|>
                        ((pDetectChar False '"' >>= withAttribute "Types") >>~ pushContext "ML_types2"))
     return (attr, result)

parseRules "ML_types1" = 
  do (attr, result) <- (((lookAhead (pDetect2Chars False '*' '/') >> return ([],"") ) >>~ (popContext))
                        <|>
                        ((pDetectChar False '\'' >>= withAttribute "Types") >>~ (popContext >> popContext)))
     return (attr, result)

parseRules "ML_types2" = 
  do (attr, result) <- (((lookAhead (pDetect2Chars False '*' '/') >> return ([],"") ) >>~ (popContext))
                        <|>
                        ((pDetectChar False '"' >>= withAttribute "Types") >>~ (popContext >> popContext)))
     return (attr, result)

parseRules "SL_TagWord" = 
  do (attr, result) <- (((pDetectSpaces >>= withAttribute "Comment"))
                        <|>
                        ((lookAhead (pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}" list_TagWord) >> return ([],"") ) >>~ (popContext))
                        <|>
                        ((pRegExpr regex_'5cS'28'3f'3d'28'5b'5d'5b'2c'3f'3b'28'29'5d'7c'5c'2e'24'7c'5c'2e'3f'5cs'29'29 >>= withAttribute "Word") >>~ (popContext))
                        <|>
                        ((pRegExpr regex_'5cS >>= withAttribute "Word")))
     return (attr, result)

parseRules "SL_TagParam" = 
  do (attr, result) <- (((pDetectSpaces >>= withAttribute "Comment"))
                        <|>
                        ((pString False "[in]" >>= withAttribute "Tags") >>~ pushContext "SL_Tag2ndWord")
                        <|>
                        ((pString False "[out]" >>= withAttribute "Tags") >>~ pushContext "SL_Tag2ndWord")
                        <|>
                        ((pString False "[in,out]" >>= withAttribute "Tags") >>~ pushContext "SL_Tag2ndWord")
                        <|>
                        ((pRegExpr regex_'5cS'28'3f'3d'28'5b'5d'5b'2c'3f'3b'28'29'5d'7c'5c'2e'24'7c'5c'2e'3f'5cs'29'29 >>= withAttribute "Word") >>~ (popContext))
                        <|>
                        ((pRegExpr regex_'5cS >>= withAttribute "Word")))
     return (attr, result)

parseRules "SL_TagWordWord" = 
  do (attr, result) <- (((pDetectSpaces >>= withAttribute "Comment"))
                        <|>
                        ((pRegExpr regex_'5cS'28'3f'3d'28'5b'5d'5b'2c'3f'3b'28'29'5d'7c'5c'2e'24'7c'5c'2e'3f'5cs'29'29 >>= withAttribute "Word") >>~ pushContext "SL_Tag2ndWord")
                        <|>
                        ((pRegExpr regex_'5cS >>= withAttribute "Word")))
     return (attr, result)

parseRules "SL_Tag2ndWord" = 
  do (attr, result) <- (((pDetectSpaces >>= withAttribute "Comment"))
                        <|>
                        ((pRegExpr regex_'5cS'28'3f'3d'28'5b'5d'5b'2c'3f'3b'28'29'5d'7c'5c'2e'24'7c'5c'2e'3f'5cs'29'29 >>= withAttribute "Word") >>~ (popContext >> popContext))
                        <|>
                        ((pRegExpr regex_'5cS >>= withAttribute "Word")))
     return (attr, result)

parseRules "SL_TagString" = 
  do (attr, result) <- (((pDetectSpaces >>= withAttribute "Comment"))
                        <|>
                        ((pString False "<!--" >>= withAttribute "HTML Comment") >>~ pushContext "SL_htmlcomment")
                        <|>
                        ((pDetect2Chars False '<' '<' >>= withAttribute "Comment"))
                        <|>
                        ((pRegExpr regex_'3c'5c'2f'3f'5ba'2dzA'2dZ'5f'3a'5d'5ba'2dzA'2dZ0'2d9'2e'5f'3a'2d'5d'2a >>= withAttribute "HTML Tag") >>~ pushContext "SL_htmltag")
                        <|>
                        ((pRegExpr regex_'2e >>= withAttribute "Description")))
     return (attr, result)

parseRules "SL_TagWordString" = 
  do (attr, result) <- (((pDetectSpaces >>= withAttribute "Comment"))
                        <|>
                        ((pRegExpr regex_'5cS'28'3f'3d'28'5b'5d'5b'2c'3f'3b'28'29'5d'7c'5c'2e'24'7c'5c'2e'3f'5cs'29'29 >>= withAttribute "Word") >>~ (popContext))
                        <|>
                        ((pRegExpr regex_'5cS >>= withAttribute "Word")))
     return (attr, result)

parseRules "SL_htmltag" = 
  do (attr, result) <- (((pDetect2Chars False '/' '>' >>= withAttribute "HTML Tag") >>~ (popContext))
                        <|>
                        ((pDetectChar False '>' >>= withAttribute "HTML Tag") >>~ (popContext))
                        <|>
                        ((pRegExpr regex_'5cs'2a'3d'5cs'2a >>= withAttribute "Identifier") >>~ pushContext "SL_identifiers"))
     return (attr, result)

parseRules "SL_htmlcomment" = 
  do (attr, result) <- (((Text.Highlighting.Kate.Syntax.Alert.parseExpression))
                        <|>
                        ((pString False "-->" >>= withAttribute "HTML Comment") >>~ (popContext)))
     return (attr, result)

parseRules "SL_identifiers" = 
  do (attr, result) <- (((pRegExpr regex_'5cs'2a'23'3f'5ba'2dzA'2dZ0'2d9'5d'2a >>= withAttribute "String") >>~ (popContext))
                        <|>
                        ((pDetectChar False '\'' >>= withAttribute "Types") >>~ pushContext "SL_types1")
                        <|>
                        ((pDetectChar False '"' >>= withAttribute "Types") >>~ pushContext "SL_types2"))
     return (attr, result)

parseRules "SL_types1" = 
  do (attr, result) <- ((pDetectChar False '\'' >>= withAttribute "Types") >>~ (popContext >> popContext))
     return (attr, result)

parseRules "SL_types2" = 
  do (attr, result) <- ((pDetectChar False '"' >>= withAttribute "Types") >>~ (popContext >> popContext))
     return (attr, result)

parseRules "SL_DetectEnv" = 
  do (attr, result) <- (((pRegExpr regex_'5b'40'5c'5c'5dcode >>= withAttribute "Tags") >>~ pushContext "Code")
                        <|>
                        ((pRegExpr regex_'5b'40'5c'5c'5dverbatim >>= withAttribute "Tags") >>~ pushContext "Verbatim")
                        <|>
                        ((pRegExpr regex_'5b'40'5c'5c'5df'5c'5b >>= withAttribute "Tags") >>~ pushContext "Formula")
                        <|>
                        ((pRegExpr regex_'5b'40'5c'5c'5dmsc >>= withAttribute "Tags") >>~ pushContext "Msc")
                        <|>
                        ((pRegExpr regex_'5b'40'5c'5c'5ddot >>= withAttribute "Tags") >>~ pushContext "Dot"))
     return (attr, result)

parseRules "SL_DetectComment" = 
  do (attr, result) <- (((pColumn 0 >> pRegExpr regex_'5cs'2a'28'5c'2a'2f'29 >>= withAttribute "Comment") >>~ (popContext >> popContext))
                        <|>
                        ((pColumn 0 >> pRegExpr regex_'5cs'2a'28'5c'2a'7c'2f'2f'28'21'7c'28'2f'28'3f'3d'5b'5e'2f'5d'7c'24'29'29'29'3c'3f'29 >>= withAttribute "Comment")))
     return (attr, result)

parseRules "Code" = 
  do (attr, result) <- (((parseRules "SL_DetectComment"))
                        <|>
                        ((pRegExpr regex_'5b'40'5c'5c'5dendcode >>= withAttribute "Tags") >>~ (popContext)))
     return (attr, result)

parseRules "Verbatim" = 
  do (attr, result) <- (((parseRules "SL_DetectComment"))
                        <|>
                        ((pRegExpr regex_'5b'40'5c'5c'5dendverbatim >>= withAttribute "Tags") >>~ (popContext)))
     return (attr, result)

parseRules "Formula" = 
  do (attr, result) <- (((parseRules "SL_DetectComment"))
                        <|>
                        ((pRegExpr regex_'5b'40'5c'5c'5df'5c'5d >>= withAttribute "Tags") >>~ (popContext)))
     return (attr, result)

parseRules "Msc" = 
  do (attr, result) <- (((parseRules "SL_DetectComment"))
                        <|>
                        ((pRegExpr regex_'5b'40'5c'5c'5dendmsc >>= withAttribute "Tags") >>~ (popContext)))
     return (attr, result)

parseRules "Dot" = 
  do (attr, result) <- (((parseRules "SL_DetectComment"))
                        <|>
                        ((pRegExpr regex_'5b'40'5c'5c'5denddot >>= withAttribute "Tags") >>~ (popContext)))
     return (attr, result)

parseRules "" = parseRules "Normal"

parseRules x = fail $ "Unknown context" ++ x