{- This module was generated from data in the Kate syntax highlighting file xslt.xml, version 1.03, by Peter Lammich (views@gmx.de) -} module Text.Highlighting.Kate.Syntax.Xslt ( highlight, parseExpression, syntaxName, syntaxExtensions ) where import Text.Highlighting.Kate.Definitions import Text.Highlighting.Kate.Common import Text.ParserCombinators.Parsec import Data.List (nub) import Data.Map (fromList) import Data.Maybe (fromMaybe) -- | Full name of language. syntaxName :: String syntaxName = "xslt" -- | Filename extensions for this language. syntaxExtensions :: String syntaxExtensions = "*.xsl;*.xslt" -- | 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 = "xslt" } context <- currentContext <|> (pushContext "normalText" >> 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 [("xslt",["normalText"])], synStLanguage = "xslt", synStCurrentLine = "", synStCharsParsedInLine = 0, synStCaseSensitive = True, synStKeywordCaseSensitive = False, synStCaptures = []} parseSourceLine = manyTill parseExpressionInternal pEndLine pEndLine = do newline <|> (eof >> return '\n') context <- currentContext case context of "normalText" -> return () "detectEntRef" -> return () "tagname" -> return () "attributes" -> return () "attrValue" -> return () "xattributes" -> return () "xattrValue" -> return () "string" -> return () "sqstring" -> return () "comment" -> return () "xpath" -> return () "sqxpath" -> return () "sqxpathstring" -> return () "xpathstring" -> return () _ -> return () lineContents <- lookAhead wholeLine updateState $ \st -> st { synStCurrentLine = lineContents, synStCharsParsedInLine = 0 } 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 updateState $ \st -> st { synStCharsParsedInLine = oldCharsParsed + length txt } return (nub [style, attr], txt) styles = [("Normal Text","Normal"),("Tag","Keyword"),("Attribute","Others"),("Invalid","Error"),("Alert","Alert"),("Attribute Value","String"),("XPath","Others"),("XPath String","String"),("XPath Axis","Keyword"),("XPath/ XSLT Function","Keyword"),("XPath 2.0/ XSLT 2.0 Function","Keyword"),("XPath Attribute","Normal"),("Variable","Normal"),("Comment","Comment"),("XSLT Tag","Keyword"),("XSLT 2.0 Tag","Keyword"),("Entity Reference","DecVal")] parseExpressionInternal = do context <- currentContext parseRules context <|> (pDefault >>= withAttribute (fromMaybe "" $ lookup context defaultAttributes)) defaultAttributes = [("normalText","Normal Text"),("detectEntRef","Normal Text"),("tagname","Tag"),("attributes","Attribute"),("attrValue","Invalid"),("xattributes","Attribute"),("xattrValue","Invalid"),("string","Attribute Value"),("sqstring","Attribute Value"),("comment","Comment"),("xpath","XPath"),("sqxpath","XPath"),("sqxpathstring","XPath String"),("xpathstring","XPath String")] parseRules "normalText" = do (attr, result) <- (((pString False "" >>= withAttribute "Comment") >>~ (popContext >> return ())) <|> ((pRegExpr (compileRegex "-(-(?!->))+") >>= withAttribute "Invalid")) <|> ((pRegExpr (compileRegex "(FIXME|TODO|HACK)") >>= withAttribute "Alert"))) return (attr, result) parseRules "xpath" = do (attr, result) <- (((pKeyword " \n\t.()!+,<=>%&*/;?[]^{|}~\\\"{}" ["format-number","position","lang","substring-before","substring","normalize-space","round","translate","starts-with","concat","local-name","key","count","document","system-property","current","boolean","number","contains","name","last","unparsed-entity-uri","sum","generate-id","function-available","element-available","false","substring-after","not","string-length","id","floor","ceiling","namespace-uri","true","string","text"] >>= withAttribute "XPath/ XSLT Function")) <|> ((pKeyword " \n\t.()!+,<=>%&*/;?[]^{|}~\\\"{}" ["zero-or-one","replace","namespace-uri-for-prefix","current-grouping-key","seconds-from-duration","resolve-uri","node-kind","minutes-from-dateTime","implicit-timezone","exactly-one","current-time","current-dateTime","unordered","subtract-dates-yielding-dayTimeDuration","string-join","static-base-uri","months-from-duration","input","exists","default-collation","dateTime","current-group","current-date","collection","timezone-from-time","matches","local-name-from-QName","day-from-date","timezone-from-date","round-half-to-even","month-from-dateTime","month-from-date","hours-from-duration","escape-uri","distinct-values","avg","years-from-duration","unparsed-text","unparsed-entity-public-id","subtract-dateTimes-yielding-dayTimeDuration","subtract-dates-yielding-yearMonthDuration","string-to-codepoints","sequence-node-identical","hours-from-time","hours-from-dateTime","format-time","codepoints-to-string","trace","tokenize","subtract-dateTimes-yielding-yearMonthDuration","subsequence","seconds-from-dateTime","regex-group","one-or-more","node-name","namespace-uri-from-QName","min","idref","format-dateTime","format-date","days-from-duration","compare","base-uri","seconds-from-time","in-scope-prefixes","expanded-QName","adjust-date-to-timezone","year-from-date","resolve-QName","remove","QName","minutes-from-time","max","lower-case","index-of","doc","deep-equal","data","minutes-from-duration","adjust-dateTime-to-timezone","abs","timezone-from-dateTime","reverse","error","ends-with","day-from-dateTime","year-from-dateTime","upper-case","root","normalize-unicode","empty","insert-before","document-uri","adjust-time-to-timezone"] >>= withAttribute "XPath 2.0/ XSLT 2.0 Function")) <|> ((pRegExpr (compileRegex "(ancestor|ancestor-or-self|attribute|child|descendant|descendant-or-self|following|following-sibling|namespace|parent|preceding|preceding-sibling|self)::") >>= withAttribute "XPath Axis")) <|> ((pDetectChar False '}' >>= withAttribute "XPath") >>~ (popContext >> return ())) <|> ((pDetectChar False '\'' >>= withAttribute "XPath String") >>~ pushContext "sqxpathstring") <|> ((pDetectChar False '"' >>= withAttribute "XPath") >>~ (popContext >> popContext >> return ())) <|> ((pRegExpr (compileRegex "@[A-Za-z_:][\\w.:_-]*") >>= withAttribute "XPath Attribute")) <|> ((pRegExpr (compileRegex "\\$[A-Za-z_:][\\w.:_-]*") >>= withAttribute "Variable")) <|> ((pRegExpr (compileRegex "[A-Za-z_:][\\w.:_-]*") >>= withAttribute "XPath")) <|> ((pDetectChar False '$' >>= withAttribute "Invalid")) <|> ((parseRules "detectEntRef"))) return (attr, result) parseRules "sqxpath" = do (attr, result) <- (((pKeyword " \n\t.()!+,<=>%&*/;?[]^{|}~\\\"{}" ["format-number","position","lang","substring-before","substring","normalize-space","round","translate","starts-with","concat","local-name","key","count","document","system-property","current","boolean","number","contains","name","last","unparsed-entity-uri","sum","generate-id","function-available","element-available","false","substring-after","not","string-length","id","floor","ceiling","namespace-uri","true","string","text"] >>= withAttribute "XPath/ XSLT Function")) <|> ((pKeyword " \n\t.()!+,<=>%&*/;?[]^{|}~\\\"{}" ["zero-or-one","replace","namespace-uri-for-prefix","current-grouping-key","seconds-from-duration","resolve-uri","node-kind","minutes-from-dateTime","implicit-timezone","exactly-one","current-time","current-dateTime","unordered","subtract-dates-yielding-dayTimeDuration","string-join","static-base-uri","months-from-duration","input","exists","default-collation","dateTime","current-group","current-date","collection","timezone-from-time","matches","local-name-from-QName","day-from-date","timezone-from-date","round-half-to-even","month-from-dateTime","month-from-date","hours-from-duration","escape-uri","distinct-values","avg","years-from-duration","unparsed-text","unparsed-entity-public-id","subtract-dateTimes-yielding-dayTimeDuration","subtract-dates-yielding-yearMonthDuration","string-to-codepoints","sequence-node-identical","hours-from-time","hours-from-dateTime","format-time","codepoints-to-string","trace","tokenize","subtract-dateTimes-yielding-yearMonthDuration","subsequence","seconds-from-dateTime","regex-group","one-or-more","node-name","namespace-uri-from-QName","min","idref","format-dateTime","format-date","days-from-duration","compare","base-uri","seconds-from-time","in-scope-prefixes","expanded-QName","adjust-date-to-timezone","year-from-date","resolve-QName","remove","QName","minutes-from-time","max","lower-case","index-of","doc","deep-equal","data","minutes-from-duration","adjust-dateTime-to-timezone","abs","timezone-from-dateTime","reverse","error","ends-with","day-from-dateTime","year-from-dateTime","upper-case","root","normalize-unicode","empty","insert-before","document-uri","adjust-time-to-timezone"] >>= withAttribute "XPath 2.0/ XSLT 2.0 Function")) <|> ((pRegExpr (compileRegex "(ancestor|ancestor-or-self|attribute|child|descendant|descendant-or-self|following|following-sibling|namespace|parent|preceding|preceding-sibling|self)::") >>= withAttribute "XPath Axis")) <|> ((pDetectChar False '}' >>= withAttribute "XPath") >>~ (popContext >> return ())) <|> ((pDetectChar False '"' >>= withAttribute "XPath String") >>~ pushContext "xpathstring") <|> ((pDetectChar False '\'' >>= withAttribute "XPath") >>~ (popContext >> popContext >> return ())) <|> ((pRegExpr (compileRegex "@[A-Za-z_:][\\w.:_-]*") >>= withAttribute "XPath Attribute")) <|> ((pRegExpr (compileRegex "\\$[A-Za-z_:][\\w.:_-]*") >>= withAttribute "Variable")) <|> ((pRegExpr (compileRegex "[A-Za-z_:][\\w.:_-]*") >>= withAttribute "XPath")) <|> ((pDetectChar False '$' >>= withAttribute "Invalid")) <|> ((parseRules "detectEntRef"))) return (attr, result) parseRules "sqxpathstring" = do (attr, result) <- (((pDetectChar False '\'' >>= withAttribute "XPath String") >>~ (popContext >> return ())) <|> ((parseRules "detectEntRef"))) return (attr, result) parseRules "xpathstring" = do (attr, result) <- (((pDetectChar False '"' >>= withAttribute "XPath String") >>~ (popContext >> return ())) <|> ((parseRules "detectEntRef"))) return (attr, result) parseRules x = fail $ "Unknown context" ++ x