{- This module was generated from data in the Kate syntax highlighting file coldfusion.xml, version 1.04,
   by   -}

module Text.Highlighting.Kate.Syntax.Coldfusion ( 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 = "ColdFusion"

-- | Filename extensions for this language.
syntaxExtensions :: String
syntaxExtensions = "*.cfm;*.cfc;*.cfml;*.dbm"

-- | 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 = "ColdFusion" }
  context <- currentContext <|> (pushContext "Normal Text" >> 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 [("ColdFusion",["Normal Text"])], synStLanguage = "ColdFusion", 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 Text" -> return ()
    "ctxCFSCRIPT Tag" -> return ()
    "ctxSCRIPT Tag" -> return ()
    "ctxSTYLE Tag" -> return ()
    "ctxTag" -> return ()
    "ctxTable Tag" -> return ()
    "ctxAnchor Tag" -> return ()
    "ctxImage Tag" -> return ()
    "ctxCF Tag" -> return ()
    "ctxCustom Tag" -> return ()
    "ctxCFX Tag" -> return ()
    "ctxHTML Comment" -> return ()
    "ctxCF Comment" -> return ()
    "ctxC Style Comment" -> return ()
    "ctxOne Line Comment" -> (popContext >> return ())
    "ctxHTML Entities" -> (popContext >> return ())
    "ctxCFSCRIPT Block" -> return ()
    "ctxSCRIPT Block" -> return ()
    "ctxSTYLE Block" -> return ()
    "ctxStyle Properties" -> return ()
    "ctxStyle Values" -> (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"),("Tags","Normal"),("Table Tags","Normal"),("Script Tags","Normal"),("Image Tags","Normal"),("Style Tags","Normal"),("Anchor Tags","Normal"),("Attribute Values","Normal"),("HTML Comment","Comment"),("CF Comment","Comment"),("Script Comment","Comment"),("CF Tags","Normal"),("Custom Tags","Normal"),("CFX Tags","Normal"),("Numbers","Normal"),("HTML Entities","Normal"),("Style Selectors","Normal"),("Style Properties","Normal"),("Style Values","Normal"),("Brackets","Normal"),("Script Numbers","Normal"),("Script Strings","Normal"),("Script Operators","Normal"),("Script Keywords","Normal"),("Script Functions","Function"),("Script Objects","Normal")]

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

list2f27b642fadc0a8e9fd44460195f9e5dcf7ae939 = Set.fromList $ words $ "if else for in while do continue break with try catch switch case new var function return this delete true false void throw typeof const default"
list58ba2bff40e5b8ae3ed0a4b4f5d06f982f7a38af = Set.fromList $ words $ "anchor applet area array boolean button checkbox date document event fileupload form frame function hidden history image layer linke location math navigator number object option password radio regexp reset screen select string submit text textarea window"
listc7b1dca2c6e21cba416149ec49ff0db638581384 = Set.fromList $ words $ "abs acos alert anchor apply asin atan atan2 back blur call captureevents ceil charat charcodeat clearinterval cleartimeout click close compile concat confirm cos disableexternalcapture enableexternalcapture eval exec exp find floor focus forward fromcharcode getdate getday getfullyear gethours getmilliseconds getminutes getmonth getseconds getselection gettime gettimezoneoffset getutcdate getutcday getutcfullyear getutchours getutcmilliseconds getutcminutes getutcmonth getutcseconds go handleevent home indexof javaenabled join lastindexof link load log match max min moveabove movebelow moveby moveto movetoabsolute open parse plugins.refresh pop pow preference print prompt push random releaseevents reload replace reset resizeby resizeto reverse round routeevent scrollby scrollto search select setdate setfullyear sethours setinterval setmilliseconds setminutes setmonth setseconds settime settimeout setutcdate setutcfullyear setutchours setutcmilliseconds setutcminutes setutcmonth setutcseconds shift sin slice sort splice split sqrt stop string formatting submit substr substring taintenabled tan test tolocalestring tolowercase tosource tostring touppercase toutcstring unshift unwatch utc valueof watch write writeln"
list191e769ac6eb67c524168739d82182adb00ac0c4 = Set.fromList $ words $ "break case catch continue default do else for function if in return switch try var while"
listb9c6c6b4ee0c8de65a6e989102027aa425d8398a = Set.fromList $ words $ "abs acos arrayappend arrayavg arrayclear arraydeleteat arrayinsertat arrayisempty arraylen arraymax arraymin arraynew arrayprepend arrayresize arrayset arraysort arraysum arrayswap arraytolist asc asin atn bitand bitmaskclear bitmaskread bitmaskset bitnot bitor bitshln bitshrn bitxor ceiling chr cjustify compare comparenocase cos createdate createdatetime createobject createodbcdate createodbcdatetime createodbctime createtime createtimespan createuuid dateadd datecompare dateconvert datediff dateformat datepart day dayofweek dayofweekasstring dayofyear daysinmonth daysinyear de decimalformat decrementvalue decrypt deleteclientvariable directoryexists dollarformat duplicate encrypt evaluate exp expandpath fileexists find findnocase findoneof firstdayofmonth fix formatbasen getauthuser getbasetagdata getbasetaglist getbasetemplatepath getclientvariableslist getcurrenttemplatepath getdirectoryfrompath getexception getfilefrompath getfunctionlist gethttprequestdata gethttptimestring getk2serverdoccount getk2serverdoccountlimit getlocale getmetadata getmetricdata getpagecontext getprofilesections getprofilestring getservicesettings gettempdirectory gettempfile gettemplatepath gettickcount gettimezoneinfo gettoken hash hour htmlcodeformat htmleditformat iif incrementvalue inputbasen insert int isarray isbinary isboolean iscustomfunction isdate isdebugmode isdefined isk2serverabroker isk2serverdoccountexceeded isk2serveronline isleapyear isnumeric isnumericdate isobject isquery issimplevalue isstruct isuserinrole iswddx isxmldoc isxmlelement isxmlroot javacast jsstringformat lcase left len listappend listchangedelims listcontains listcontainsnocase listdeleteat listfind listfindnocase listfirst listgetat listinsertat listlast listlen listprepend listqualify listrest listsetat listsort listtoarray listvaluecount listvaluecountnocase ljustify log log10 lscurrencyformat lsdateformat lseurocurrencyformat lsiscurrency lsisdate lsisnumeric lsnumberformat lsparsecurrency lsparsedatetime lsparseeurocurrency lsparsenumber lstimeformat ltrim max mid min minute month monthasstring now numberformat paragraphformat parameterexists parsedatetime pi preservesinglequotes quarter queryaddcolumn queryaddrow querynew querysetcell quotedvaluelist rand randomize randrange refind refindnocase removechars repeatstring replace replacelist replacenocase rereplace rereplacenocase reverse right rjustify round rtrim second setencoding setlocale setprofilestring setvariable sgn sin spanexcluding spanincluding sqr stripcr structappend structclear structcopy structcount structdelete structfind structfindkey structfindvalue structget structinsert structisempty structkeyarray structkeyexists structkeylist structnew structsort structupdate tan timeformat tobase64 tobinary tostring trim ucase urldecode urlencodedformat urlsessionformat val valuelist week writeoutput xmlchildpos xmlelemnew xmlformat xmlnew xmlparse xmlsearch xmltransform year yesnoformat"

defaultAttributes = [("Normal Text","Normal Text"),("ctxCFSCRIPT Tag","Script Tags"),("ctxSCRIPT Tag","Script Tags"),("ctxSTYLE Tag","Style Tags"),("ctxTag","Tags"),("ctxTable Tag","Table Tags"),("ctxAnchor Tag","Anchor Tags"),("ctxImage Tag","Image Tags"),("ctxCF Tag","CF Tags"),("ctxCustom Tag","Custom Tags"),("ctxCFX Tag","CFX Tags"),("ctxHTML Comment","HTML Comment"),("ctxCF Comment","CF Comment"),("ctxC Style Comment","Script Comment"),("ctxOne Line Comment","Script Comment"),("ctxHTML Entities","HTML Entities"),("ctxCFSCRIPT Block","Normal Text"),("ctxSCRIPT Block","Normal Text"),("ctxSTYLE Block","Style Selectors"),("ctxStyle Properties","Style Properties"),("ctxStyle Values","Style Values")]

parseRules "Normal Text" = 
  do (attr, result) <- (((pString False "<!---" >>= withAttribute "CF Comment") >>~ pushContext "ctxCF Comment")
                        <|>
                        ((pString False "<!--" >>= withAttribute "HTML Comment") >>~ pushContext "ctxHTML Comment")
                        <|>
                        ((pRegExpr (compileRegex "<[cC][fF][sS][cC][rR][iI][pP][tT]") >>= withAttribute "Script Tags") >>~ pushContext "ctxCFSCRIPT Tag")
                        <|>
                        ((pRegExpr (compileRegex "<[sS][cC][rR][iI][pP][tT]") >>= withAttribute "Script Tags") >>~ pushContext "ctxSCRIPT Tag")
                        <|>
                        ((pRegExpr (compileRegex "<[sS][tT][yY][lL][eE]") >>= withAttribute "Style Tags") >>~ pushContext "ctxSTYLE Tag")
                        <|>
                        ((pDetectChar False '&' >>= withAttribute "HTML Entities") >>~ pushContext "ctxHTML Entities")
                        <|>
                        ((pRegExpr (compileRegex "<\\/?[cC][fF]_") >>= withAttribute "Custom Tags") >>~ pushContext "ctxCustom Tag")
                        <|>
                        ((pRegExpr (compileRegex "<\\/?[cC][fF][xX]_") >>= withAttribute "CFX Tags") >>~ pushContext "ctxCFX Tag")
                        <|>
                        ((pRegExpr (compileRegex "<\\/?[cC][fF]") >>= withAttribute "CF Tags") >>~ pushContext "ctxCF Tag")
                        <|>
                        ((pRegExpr (compileRegex "<\\/?([tT][aAhHbBfFrRdD])|([cC][aA][pP][tT])") >>= withAttribute "Table Tags") >>~ pushContext "ctxTable Tag")
                        <|>
                        ((pRegExpr (compileRegex "<\\/?[aA] ") >>= withAttribute "Anchor Tags") >>~ pushContext "ctxAnchor Tag")
                        <|>
                        ((pRegExpr (compileRegex "<\\/?[iI][mM][gG] ") >>= withAttribute "Image Tags") >>~ pushContext "ctxImage Tag")
                        <|>
                        ((pRegExpr (compileRegex "<!?\\/?[a-zA-Z0-9_]+") >>= withAttribute "Tags") >>~ pushContext "ctxTag"))
     return (attr, result)

parseRules "ctxCFSCRIPT Tag" = 
  do (attr, result) <- (((pDetectChar False '>' >>= withAttribute "Script Tags") >>~ pushContext "ctxCFSCRIPT Block")
                        <|>
                        ((pDetectChar False '=' >>= withAttribute "Normal Text"))
                        <|>
                        ((pRegExpr (compileRegex "\"[^\"]*\"") >>= withAttribute "Attribute Values"))
                        <|>
                        ((pRegExpr (compileRegex "'[^']*'") >>= withAttribute "Attribute Values")))
     return (attr, result)

parseRules "ctxSCRIPT Tag" = 
  do (attr, result) <- (((pDetectChar False '>' >>= withAttribute "Script Tags") >>~ pushContext "ctxSCRIPT Block")
                        <|>
                        ((pDetectChar False '=' >>= withAttribute "Normal Text"))
                        <|>
                        ((pRegExpr (compileRegex "\"[^\"]*\"") >>= withAttribute "Attribute Values"))
                        <|>
                        ((pRegExpr (compileRegex "'[^']*'") >>= withAttribute "Attribute Values")))
     return (attr, result)

parseRules "ctxSTYLE Tag" = 
  do (attr, result) <- (((pDetectChar False '>' >>= withAttribute "Style Tags") >>~ pushContext "ctxSTYLE Block")
                        <|>
                        ((pDetectChar False '=' >>= withAttribute "Normal Text"))
                        <|>
                        ((pRegExpr (compileRegex "\"[^\"]*\"") >>= withAttribute "Attribute Values"))
                        <|>
                        ((pRegExpr (compileRegex "'[^']*'") >>= withAttribute "Attribute Values")))
     return (attr, result)

parseRules "ctxTag" = 
  do (attr, result) <- (((pDetectChar False '>' >>= withAttribute "Tags") >>~ (popContext >> return ()))
                        <|>
                        ((pDetectChar False '=' >>= withAttribute "Normal Text"))
                        <|>
                        ((pRegExpr (compileRegex "\"[^\"]*\"") >>= withAttribute "Attribute Values"))
                        <|>
                        ((pRegExpr (compileRegex "'[^']*'") >>= withAttribute "Attribute Values")))
     return (attr, result)

parseRules "ctxTable Tag" = 
  do (attr, result) <- (((pDetectChar False '>' >>= withAttribute "Table Tags") >>~ (popContext >> return ()))
                        <|>
                        ((pDetectChar False '=' >>= withAttribute "Normal Text"))
                        <|>
                        ((pRegExpr (compileRegex "\"[^\"]*\"") >>= withAttribute "Attribute Values"))
                        <|>
                        ((pRegExpr (compileRegex "'[^']*'") >>= withAttribute "Attribute Values")))
     return (attr, result)

parseRules "ctxAnchor Tag" = 
  do (attr, result) <- (((pDetectChar False '>' >>= withAttribute "Anchor Tags") >>~ (popContext >> return ()))
                        <|>
                        ((pDetectChar False '=' >>= withAttribute "Normal Text"))
                        <|>
                        ((pRegExpr (compileRegex "\"[^\"]*\"") >>= withAttribute "Attribute Values"))
                        <|>
                        ((pRegExpr (compileRegex "'[^']*'") >>= withAttribute "Attribute Values")))
     return (attr, result)

parseRules "ctxImage Tag" = 
  do (attr, result) <- (((pDetectChar False '>' >>= withAttribute "Image Tags") >>~ (popContext >> return ()))
                        <|>
                        ((pDetectChar False '=' >>= withAttribute "Normal Text"))
                        <|>
                        ((pRegExpr (compileRegex "\"[^\"]*\"") >>= withAttribute "Attribute Values"))
                        <|>
                        ((pRegExpr (compileRegex "'[^']*'") >>= withAttribute "Attribute Values")))
     return (attr, result)

parseRules "ctxCF Tag" = 
  do (attr, result) <- (((pDetectChar False '>' >>= withAttribute "CF Tags") >>~ (popContext >> return ()))
                        <|>
                        ((pDetectChar False '=' >>= withAttribute "Normal Text"))
                        <|>
                        ((pRegExpr (compileRegex "\"[^\"]*\"") >>= withAttribute "Attribute Values"))
                        <|>
                        ((pRegExpr (compileRegex "'[^']*'") >>= withAttribute "Attribute Values")))
     return (attr, result)

parseRules "ctxCustom Tag" = 
  do (attr, result) <- (((pDetectChar False '>' >>= withAttribute "Custom Tags") >>~ (popContext >> return ()))
                        <|>
                        ((pDetectChar False '=' >>= withAttribute "Normal Text"))
                        <|>
                        ((pRegExpr (compileRegex "\"[^\"]*\"") >>= withAttribute "Attribute Values"))
                        <|>
                        ((pRegExpr (compileRegex "'[^']*'") >>= withAttribute "Attribute Values")))
     return (attr, result)

parseRules "ctxCFX Tag" = 
  do (attr, result) <- (((pDetectChar False '>' >>= withAttribute "CFX Tags") >>~ (popContext >> return ()))
                        <|>
                        ((pDetectChar False '=' >>= withAttribute "Normal Text"))
                        <|>
                        ((pRegExpr (compileRegex "\"[^\"]*\"") >>= withAttribute "Attribute Values"))
                        <|>
                        ((pRegExpr (compileRegex "'[^']*'") >>= withAttribute "Attribute Values")))
     return (attr, result)

parseRules "ctxHTML Comment" = 
  do (attr, result) <- (((pString False "<!---" >>= withAttribute "CF Comment") >>~ pushContext "ctxCF Comment")
                        <|>
                        ((pString False "-->" >>= withAttribute "HTML Comment") >>~ (popContext >> return ())))
     return (attr, result)

parseRules "ctxCF Comment" = 
  do (attr, result) <- ((pString False "--->" >>= withAttribute "CF Comment") >>~ (popContext >> return ()))
     return (attr, result)

parseRules "ctxC Style Comment" = 
  do (attr, result) <- ((pDetect2Chars False '*' '/' >>= withAttribute "Script Comment") >>~ (popContext >> return ()))
     return (attr, result)

parseRules "ctxOne Line Comment" = 
  pzero

parseRules "ctxHTML Entities" = 
  do (attr, result) <- ((pDetectChar False ';' >>= withAttribute "HTML Entities") >>~ (popContext >> return ()))
     return (attr, result)

parseRules "ctxCFSCRIPT Block" = 
  do (attr, result) <- (((pDetect2Chars False '/' '*' >>= withAttribute "Script Comment") >>~ pushContext "ctxC Style Comment")
                        <|>
                        ((pDetect2Chars False '/' '/' >>= withAttribute "Script Comment") >>~ pushContext "ctxOne Line Comment")
                        <|>
                        ((pRegExpr (compileRegex "\"[^\"]*\"") >>= withAttribute "Script Strings"))
                        <|>
                        ((pRegExpr (compileRegex "'[^']*'") >>= withAttribute "Script Strings"))
                        <|>
                        ((pInt >>= withAttribute "Script Numbers"))
                        <|>
                        ((pFloat >>= withAttribute "Script Numbers"))
                        <|>
                        ((pAnyChar "[()[\\]=+-*/]+" >>= withAttribute "Script Operators"))
                        <|>
                        ((pAnyChar "{}" >>= withAttribute "Brackets"))
                        <|>
                        ((pKeyword " \n\t.():!+,<=>%&*/;?[]^{|}~\\" list191e769ac6eb67c524168739d82182adb00ac0c4 >>= withAttribute "Script Keywords"))
                        <|>
                        ((pKeyword " \n\t.():!+,<=>%&*/;?[]^{|}~\\" listb9c6c6b4ee0c8de65a6e989102027aa425d8398a >>= withAttribute "Script Functions"))
                        <|>
                        ((pRegExpr (compileRegex "</[cC][fF][sS][cC][rR][iI][pP][tT]>") >>= withAttribute "Script Tags") >>~ (popContext >> popContext >> return ())))
     return (attr, result)

parseRules "ctxSCRIPT Block" = 
  do (attr, result) <- (((pDetect2Chars False '/' '*' >>= withAttribute "Script Comment") >>~ pushContext "ctxC Style Comment")
                        <|>
                        ((pDetect2Chars False '/' '/' >>= withAttribute "Script Comment") >>~ pushContext "ctxOne Line Comment")
                        <|>
                        ((pRegExpr (compileRegex "\"[^\"]*\"") >>= withAttribute "Script Strings"))
                        <|>
                        ((pRegExpr (compileRegex "'[^']*'") >>= withAttribute "Script Strings"))
                        <|>
                        ((pInt >>= withAttribute "Script Numbers"))
                        <|>
                        ((pFloat >>= withAttribute "Script Numbers"))
                        <|>
                        ((pAnyChar "[()[\\]=+-*/]+" >>= withAttribute "Script Operators"))
                        <|>
                        ((pAnyChar "{}" >>= withAttribute "Brackets"))
                        <|>
                        ((pKeyword " \n\t.():!+,<=>%&*/;?[]^{|}~\\" list2f27b642fadc0a8e9fd44460195f9e5dcf7ae939 >>= withAttribute "Script Keywords"))
                        <|>
                        ((pKeyword " \n\t.():!+,<=>%&*/;?[]^{|}~\\" list58ba2bff40e5b8ae3ed0a4b4f5d06f982f7a38af >>= withAttribute "Script Objects"))
                        <|>
                        ((pKeyword " \n\t.():!+,<=>%&*/;?[]^{|}~\\" listc7b1dca2c6e21cba416149ec49ff0db638581384 >>= withAttribute "Script Functions"))
                        <|>
                        ((pRegExpr (compileRegex "</[sS][cC][rR][iI][pP][tT]>") >>= withAttribute "Script Tags") >>~ (popContext >> popContext >> return ())))
     return (attr, result)

parseRules "ctxSTYLE Block" = 
  do (attr, result) <- (((pDetect2Chars False '/' '*' >>= withAttribute "Script Comment") >>~ pushContext "ctxC Style Comment")
                        <|>
                        ((pDetectChar False '{' >>= withAttribute "Brackets") >>~ pushContext "ctxStyle Properties")
                        <|>
                        ((pRegExpr (compileRegex "</[sS][tT][yY][lL][eE]>") >>= withAttribute "Style Tags") >>~ (popContext >> popContext >> return ())))
     return (attr, result)

parseRules "ctxStyle Properties" = 
  do (attr, result) <- (((pDetectChar False '}' >>= withAttribute "Brackets") >>~ (popContext >> return ()))
                        <|>
                        ((pDetect2Chars False '/' '*' >>= withAttribute "Script Comment") >>~ pushContext "ctxC Style Comment")
                        <|>
                        ((pDetectChar False ':' >>= withAttribute "Normal Text") >>~ pushContext "ctxStyle Values"))
     return (attr, result)

parseRules "ctxStyle Values" = 
  do (attr, result) <- (((pDetectChar False ';' >>= withAttribute "Normal Text") >>~ (popContext >> return ()))
                        <|>
                        ((pDetectChar False ',' >>= withAttribute "Normal Text"))
                        <|>
                        ((pInt >>= withAttribute "Numbers"))
                        <|>
                        ((pFloat >>= withAttribute "Numbers"))
                        <|>
                        ((pRegExpr (compileRegex "#([0-9a-fA-F]{3})|([0-9a-fA-F]{6})") >>= withAttribute "Numbers"))
                        <|>
                        ((pRegExpr (compileRegex "\"[^\"]*\"") >>= withAttribute "Attribute Values"))
                        <|>
                        ((pRegExpr (compileRegex "'[^']*'") >>= withAttribute "Attribute Values")))
     return (attr, result)

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