module Text.Highlighting.Kate.Syntax.Alert_indent
(highlight, parseExpression, syntaxName, syntaxExtensions)
where
import Text.Highlighting.Kate.Types
import Text.Highlighting.Kate.Common
import Text.ParserCombinators.Parsec hiding (State)
import Control.Monad.State
import Data.Char (isSpace)
import Data.Maybe (fromMaybe)
import qualified Data.Set as Set
syntaxName :: String
syntaxName = "Alerts_indent"
syntaxExtensions :: String
syntaxExtensions = ""
highlight :: String -> [SourceLine]
highlight input = evalState (mapM parseSourceLine $ lines input) startingState
parseSourceLine :: String -> State SyntaxState SourceLine
parseSourceLine = mkParseSourceLine parseExpression
parseExpression :: KateParser Token
parseExpression = do
(lang,cont) <- currentContext
result <- parseRules (lang,cont)
optional $ do eof
updateState $ \st -> st{ synStPrevChar = '\n' }
pEndLine
return result
startingState = SyntaxState {synStContexts = [("Alerts_indent","Normal Text")], synStLineNumber = 0, synStPrevChar = '\n', synStPrevNonspace = False, synStCaseSensitive = True, synStKeywordCaseSensitive = True, synStCaptures = []}
pEndLine = do
updateState $ \st -> st{ synStPrevNonspace = False }
context <- currentContext
case context of
("Alerts_indent","Normal Text") -> (popContext) >> pEndLine
_ -> 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)
list_alerts = Set.fromList $ words $ "### ALERT BUG DANGER DEPRECATED FIXME HACK NOTE NOTICE SECURITY TASK TEST TESTING TODO WARNING"
defaultAttributes = [(("Alerts_indent","Normal Text"),NormalTok)]
parseRules ("Alerts_indent","Normal Text") =
(((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}~\\" list_alerts >>= withAttribute AlertTok))
<|>
(currentContext >>= \x -> guard (x == ("Alerts_indent","Normal Text")) >> pDefault >>= withAttribute (fromMaybe NormalTok $ lookup ("Alerts_indent","Normal Text") defaultAttributes)))
parseRules x = parseRules ("Alerts_indent","Normal Text") <|> fail ("Unknown context" ++ show x)