{- This module was generated from data in the Kate syntax highlighting file html.xml, version 1.99, by Wilbert Berendsen (wilbert@kde.nl) -} module Text.Highlighting.Kate.Syntax.Html (highlight, parseExpression, syntaxName, syntaxExtensions) where import Text.Highlighting.Kate.Types import Text.Highlighting.Kate.Common import qualified Text.Highlighting.Kate.Syntax.Alert import qualified Text.Highlighting.Kate.Syntax.Css import qualified Text.Highlighting.Kate.Syntax.Javascript import Text.ParserCombinators.Parsec hiding (State) import Control.Monad.State import Data.Char (isSpace) import Data.Maybe (fromMaybe) -- | Full name of language. syntaxName :: String syntaxName = "HTML" -- | Filename extensions for this language. syntaxExtensions :: String syntaxExtensions = "*.htm;*.html;*.shtml;*.shtm" -- | Highlight source code using this syntax definition. highlight :: String -> [SourceLine] highlight input = evalState (mapM parseSourceLine $ lines input) startingState parseSourceLine :: String -> State SyntaxState SourceLine parseSourceLine = mkParseSourceLine parseExpression -- | Parse an expression using appropriate local context. parseExpression :: KateParser Token parseExpression = do (lang,cont) <- currentContext let defAttr = fromMaybe NormalTok $ lookup (lang,cont) defaultAttributes result <- if lang == "HTML" then parseRules (lang,cont) <|> (pDefault >>= withAttribute defAttr) else parseRules ("HTML","Start") optional $ do eof updateState $ \st -> st{ synStPrevChar = '\n' } pEndLine return result startingState = SyntaxState {synStContexts = [("HTML","Start")], synStLineNumber = 0, synStPrevChar = '\n', synStPrevNonspace = False, synStCaseSensitive = True, synStKeywordCaseSensitive = True, synStCaptures = []} pEndLine = do updateState $ \st -> st{ synStPrevNonspace = False } context <- currentContext case context of ("HTML","Start") -> return () ("HTML","FindHTML") -> return () ("HTML","FindEntityRefs") -> return () ("HTML","FindPEntityRefs") -> return () ("HTML","FindAttributes") -> return () ("HTML","FindDTDRules") -> return () ("HTML","Comment") -> return () ("HTML","CDATA") -> return () ("HTML","PI") -> return () ("HTML","Doctype") -> return () ("HTML","Doctype Internal Subset") -> return () ("HTML","Doctype Markupdecl") -> return () ("HTML","Doctype Markupdecl DQ") -> return () ("HTML","Doctype Markupdecl SQ") -> return () ("HTML","El Open") -> return () ("HTML","El Close") -> return () ("HTML","El Close 2") -> return () ("HTML","El Close 3") -> return () ("HTML","CSS") -> return () ("HTML","CSS content") -> return () ("HTML","JS") -> return () ("HTML","JS content") -> return () ("HTML","JS comment close") -> (popContext) >> pEndLine ("HTML","Value") -> return () ("HTML","Value NQ") -> (popContext >> popContext) >> pEndLine ("HTML","Value DQ") -> return () ("HTML","Value SQ") -> return () _ -> return () withAttribute attr txt = do when (null txt) $ fail "Parser matched no text" updateState $ \st -> st { synStPrevChar = last txt , synStPrevNonspace = synStPrevNonspace st || not (all isSpace txt) } return (attr, txt) regex_'3c'21DOCTYPE'5cs'2b = compileRegex "))+" regex_'5cS = compileRegex "\\S" regex_'3c'2fstyle'5cb = compileRegex ")" regex_'5b'5e'2f'3e'3c'22'27'5cs'5d = compileRegex "[^/><\"'\\s]" defaultAttributes = [(("HTML","Start"),NormalTok),(("HTML","FindHTML"),NormalTok),(("HTML","FindEntityRefs"),NormalTok),(("HTML","FindPEntityRefs"),NormalTok),(("HTML","FindAttributes"),NormalTok),(("HTML","FindDTDRules"),NormalTok),(("HTML","Comment"),CommentTok),(("HTML","CDATA"),NormalTok),(("HTML","PI"),NormalTok),(("HTML","Doctype"),NormalTok),(("HTML","Doctype Internal Subset"),NormalTok),(("HTML","Doctype Markupdecl"),NormalTok),(("HTML","Doctype Markupdecl DQ"),StringTok),(("HTML","Doctype Markupdecl SQ"),StringTok),(("HTML","El Open"),NormalTok),(("HTML","El Close"),NormalTok),(("HTML","El Close 2"),NormalTok),(("HTML","El Close 3"),NormalTok),(("HTML","CSS"),NormalTok),(("HTML","CSS content"),NormalTok),(("HTML","JS"),NormalTok),(("HTML","JS content"),NormalTok),(("HTML","JS comment close"),CommentTok),(("HTML","Value"),NormalTok),(("HTML","Value NQ"),NormalTok),(("HTML","Value DQ"),StringTok),(("HTML","Value SQ"),StringTok)] parseRules ("HTML","Start") = ((parseRules ("HTML","FindHTML"))) parseRules ("HTML","FindHTML") = (((pDetectSpaces >>= withAttribute NormalTok)) <|> ((pDetectIdentifier >>= withAttribute NormalTok)) <|> ((pString False "" >>= withAttribute CommentTok) >>~ (popContext)) <|> ((pRegExpr regex_'2d'28'2d'28'3f'21'2d'3e'29'29'2b >>= withAttribute ErrorTok))) parseRules ("HTML","CDATA") = (((pDetectSpaces >>= withAttribute NormalTok)) <|> ((pDetectIdentifier >>= withAttribute NormalTok)) <|> ((pString False "]]>" >>= withAttribute BaseNTok) >>~ (popContext)) <|> ((pString False "]]>" >>= withAttribute DecValTok))) parseRules ("HTML","PI") = ((pDetect2Chars False '?' '>' >>= withAttribute KeywordTok) >>~ (popContext)) parseRules ("HTML","Doctype") = (((pDetectChar False '>' >>= withAttribute DataTypeTok) >>~ (popContext)) <|> ((pDetectChar False '[' >>= withAttribute DataTypeTok) >>~ pushContext ("HTML","Doctype Internal Subset"))) parseRules ("HTML","Doctype Internal Subset") = (((pDetectChar False ']' >>= withAttribute DataTypeTok) >>~ (popContext)) <|> ((parseRules ("HTML","FindDTDRules"))) <|> ((pString False "