{- This module was generated from data in the Kate syntax highlighting file pascal.xml, version 1.21, by -} module Text.Highlighting.Kate.Syntax.Pascal ( highlight, parseExpression, syntaxName, syntaxExtensions ) where import Text.Highlighting.Kate.Definitions import Text.Highlighting.Kate.Common import Text.ParserCombinators.Parsec import Data.List (nub) import qualified Data.Set as Set import Data.Map (fromList) import Data.Maybe (fromMaybe) -- | Full name of language. syntaxName :: String syntaxName = "Pascal" -- | Filename extensions for this language. syntaxExtensions :: String syntaxExtensions = "*.pp;*.pas;*.p" -- | 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 = "Pascal" } 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 [("Pascal",["Normal"])], synStLanguage = "Pascal", synStCurrentLine = "", synStCharsParsedInLine = 0, synStPrevChar = '\n', synStCaseSensitive = True, synStKeywordCaseSensitive = False, synStCaptures = []} parseSourceLine = manyTill parseExpressionInternal pEndLine pEndLine = do newline <|> (eof >> return '\n') context <- currentContext case context of "Normal" -> return () "String" -> (popContext >> return ()) "Prep1" -> (popContext >> return ()) "Prep2" -> (popContext >> return ()) "Comment1" -> return () "Comment2" -> return () "Comment3" -> (popContext >> return ()) _ -> return () lineContents <- lookAhead wholeLine updateState $ \st -> st { synStCurrentLine = lineContents, synStCharsParsedInLine = 0, synStPrevChar = '\n' } withAttribute attr txt = do if null txt then fail "Parser matched no text" else return () let style = fromMaybe "" $ 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 (nub [style, attr], txt) styles = [("Normal Text","Normal"),("Keyword","Keyword"),("ISO/Delphi Extended","Keyword"),("Type","DataType"),("Number","DecVal"),("String","String"),("Directive","Others"),("Comment","Comment"),("Alert","Alert")] parseExpressionInternal = do context <- currentContext parseRules context <|> (pDefault >>= withAttribute (fromMaybe "" $ lookup context defaultAttributes)) list231d267383e39ad301a296ea014ee7b76a297476 = Set.fromList $ words $ "and array asm case const div do downto else file for function goto if in label mod nil not of operator or packed procedure program record repeat set then to type unit until uses var while with xor at automated break continue dispinterface dispose exit false finalization initialization library new published resourcestring self true" list9e6abdbdc7523a8b842f7348f1b8466c6724275b = Set.fromList $ words $ "abstract as bindable constructor destructor except export finally import implementation inherited inline interface is module on only otherwise override private property protected public read qualified raise restricted shl shr threadvar try virtual write" listd2c9a34f3d7cc7512faee1333aa09a4fa6a42ee5 = Set.fromList $ words $ "integer cardinal shortint smallint longint int64 byte word longword char ansichar widechar boolean bytebool wordbool longbool single double extended comp currency real real48 string shortstring ansistring widestring pointer variant file text" list1992482128d6da8a5d77fcb29071edaf099e7364 = Set.fromList $ words $ "fixme todo ###" defaultAttributes = [("Normal","Normal Text"),("String","String"),("Prep1","Directive"),("Prep2","Directive"),("Comment1","Comment"),("Comment2","Comment"),("Comment3","Comment")] parseRules "Normal" = do (attr, result) <- (((pRegExpr (compileRegex "\\b(begin|case|record)(?=(\\{[^}]*(\\}|$)|\\(\\*.*(\\*\\)|$))*([\\s]|$|//))") >>= withAttribute "Keyword")) <|> ((pRegExpr (compileRegex "\\b((object|class)(?=(\\(.*\\))?(\\{[^}]*(\\}|$)|\\(\\*.*(\\*\\)|$))*;?([\\s]|$|//))|try(?=(\\{[^}]*(\\}|$)|\\(\\*.*(\\*\\)|$))*([\\s]|$|//)))") >>= withAttribute "ISO/Delphi Extended")) <|> ((pRegExpr (compileRegex "\\bend(?=((\\{[^}]*(\\}|$)|\\(\\*.*(\\*\\)|$))*)([.;\\s]|$)|//|$)") >>= withAttribute "Keyword")) <|> ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}~\\" list231d267383e39ad301a296ea014ee7b76a297476 >>= withAttribute "Keyword")) <|> ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}~\\" list9e6abdbdc7523a8b842f7348f1b8466c6724275b >>= withAttribute "ISO/Delphi Extended")) <|> ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}~\\" listd2c9a34f3d7cc7512faee1333aa09a4fa6a42ee5 >>= withAttribute "Type")) <|> ((pFloat >>= withAttribute "Number")) <|> ((pInt >>= withAttribute "Number")) <|> ((pDetectChar False '\'' >>= withAttribute "String") >>~ pushContext "String") <|> ((pString False "(*$" >>= withAttribute "Directive") >>~ pushContext "Prep1") <|> ((pDetect2Chars False '{' '$' >>= withAttribute "Directive") >>~ pushContext "Prep2") <|> ((pDetectChar False '{' >>= withAttribute "Comment") >>~ pushContext "Comment1") <|> ((pDetect2Chars False '(' '*' >>= withAttribute "Comment") >>~ pushContext "Comment2") <|> ((pDetect2Chars False '/' '/' >>= withAttribute "Comment") >>~ pushContext "Comment3")) return (attr, result) parseRules "String" = do (attr, result) <- ((pDetectChar False '\'' >>= withAttribute "String") >>~ (popContext >> return ())) return (attr, result) parseRules "Prep1" = do (attr, result) <- ((pDetect2Chars False '*' ')' >>= withAttribute "Directive") >>~ (popContext >> return ())) return (attr, result) parseRules "Prep2" = do (attr, result) <- ((pDetectChar False '}' >>= withAttribute "Directive") >>~ (popContext >> return ())) return (attr, result) parseRules "Comment1" = do (attr, result) <- (((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}~\\" list1992482128d6da8a5d77fcb29071edaf099e7364 >>= withAttribute "Alert")) <|> ((pDetectChar False '}' >>= withAttribute "Comment") >>~ (popContext >> return ()))) return (attr, result) parseRules "Comment2" = do (attr, result) <- (((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}~\\" list1992482128d6da8a5d77fcb29071edaf099e7364 >>= withAttribute "Alert")) <|> ((pDetect2Chars False '*' ')' >>= withAttribute "Comment") >>~ (popContext >> return ()))) return (attr, result) parseRules "Comment3" = do (attr, result) <- ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}~\\" list1992482128d6da8a5d77fcb29071edaf099e7364 >>= withAttribute "Alert")) return (attr, result) parseRules x = fail $ "Unknown context" ++ x