{- This module was generated from data in the Kate syntax highlighting file haxe.xml, version 0.1, by Chad Joan -} module Text.Highlighting.Kate.Syntax.Haxe (highlight, parseExpression, syntaxName, syntaxExtensions) where import Text.Highlighting.Kate.Types import Text.Highlighting.Kate.Common import Text.ParserCombinators.Parsec hiding (State) import Data.Map (fromList) import Control.Monad.State import Data.Char (isSpace) import Data.Maybe (fromMaybe) import qualified Data.Set as Set -- | Full name of language. syntaxName :: String syntaxName = "Haxe" -- | Filename extensions for this language. syntaxExtensions :: String syntaxExtensions = "*.hx;*.Hx;*.hX;*.HX;" -- | 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 parseExpressionInternal pEndLine -- | Parse an expression using appropriate local context. parseExpression :: KateParser Token parseExpression = do st <- getState let oldLang = synStLanguage st setState $ st { synStLanguage = "Haxe" } context <- currentContext <|> (pushContext "normal" >> currentContext) result <- parseRules context optional $ eof >> pEndLine updateState $ \st -> st { synStLanguage = oldLang } return result startingState = SyntaxState {synStContexts = fromList [("Haxe",["normal"])], synStLanguage = "Haxe", synStLineNumber = 0, synStPrevChar = '\n', synStPrevNonspace = False, synStCaseSensitive = True, synStKeywordCaseSensitive = True, synStCaptures = []} pEndLine = do updateState $ \st -> st{ synStPrevNonspace = False } context <- currentContext case context of "normal" -> return () "ModuleName" -> return () "RawString" -> return () "String" -> return () "CommentLine" -> (popContext) >> pEndLine "CommentBlock" -> 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) parseExpressionInternal = do context <- currentContext parseRules context <|> (pDefault >>= withAttribute (fromMaybe NormalTok $ lookup context defaultAttributes)) list_keywords = Set.fromList $ words $ "break case cast catch class continue default else enum extends false for function if implements in inline interface new null override private public return static super switch this throw trace true try typedef untyped var while" list_modules = Set.fromList $ words $ "package import" list_types = Set.fromList $ words $ "Array Void Bool Int UInt Float Dynamic String List Error Unknown Type" regex_'23if'28'5cs'2b'5cw'2b'29'3f = compileRegex "#if(\\s+\\w+)?" regex_'23'28else'7celseif'7cend'7cerror'29 = compileRegex "#(else|elseif|end|error)" regex_'5b'5cd'5d'5b'5cd'5d'2a'28'5c'2e'28'3f'21'5c'2e'29'5b'5cd'5d'2a'28'5beE'5d'5b'2d'2b'5d'3f'5b'5cd'5d'2b'29'3f'29 = compileRegex "[\\d][\\d]*(\\.(?!\\.)[\\d]*([eE][-+]?[\\d]+)?)" regex_'5c'2e'5b'5cd'5d'5b'5cd'5d'2a'28'5beE'5d'5b'2d'2b'5d'3f'5b'5cd'5d'2b'29'3f = compileRegex "\\.[\\d][\\d]*([eE][-+]?[\\d]+)?" regex_0'5bxX'5d'5b'5cda'2dfA'2dF'5d'2b = compileRegex "0[xX][\\da-fA-F]+" regex_'5cd'2b = compileRegex "\\d+" regex_'5b'5e'5cs'5cw'2e'3a'2c'5d = compileRegex "[^\\s\\w.:,]" regex_'5c'5c'28u'5b'5cda'2dfA'2dF'5d'7b4'7d'7cU'5b'5cda'2dfA'2dF'5d'7b8'7d'7c'26'5ba'2dzA'2dZ'5d'5cw'2b'3b'29 = compileRegex "\\\\(u[\\da-fA-F]{4}|U[\\da-fA-F]{8}|&[a-zA-Z]\\w+;)" defaultAttributes = [("normal",NormalTok),("ModuleName",NormalTok),("RawString",StringTok),("String",StringTok),("CommentLine",CommentTok),("CommentBlock",CommentTok)] parseRules "normal" = (((pRegExpr regex_'23if'28'5cs'2b'5cw'2b'29'3f >>= withAttribute OtherTok) >>~ (popContext)) <|> ((pRegExpr regex_'23'28else'7celseif'7cend'7cerror'29 >>= withAttribute OtherTok) >>~ (popContext)) <|> ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}~\\" list_keywords >>= withAttribute KeywordTok)) <|> ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}~\\" list_modules >>= withAttribute KeywordTok) >>~ pushContext "ModuleName") <|> ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}~\\" list_types >>= withAttribute DataTypeTok)) <|> ((pDetectIdentifier >>= withAttribute NormalTok)) <|> ((pHlCStringChar >>= withAttribute NormalTok) >>~ (popContext)) <|> ((pDetectChar False '\'' >>= withAttribute StringTok) >>~ pushContext "RawString") <|> ((pDetectChar False '"' >>= withAttribute StringTok) >>~ pushContext "String") <|> ((pDetect2Chars False '/' '/' >>= withAttribute CommentTok) >>~ pushContext "CommentLine") <|> ((pDetect2Chars False '/' '*' >>= withAttribute CommentTok) >>~ pushContext "CommentBlock") <|> ((pDetectChar False '{' >>= withAttribute NormalTok)) <|> ((pDetectChar False '}' >>= withAttribute NormalTok)) <|> ((pString False "..." >>= withAttribute NormalTok) >>~ (popContext)) <|> ((pDetect2Chars False '.' '.' >>= withAttribute NormalTok)) <|> ((pRegExpr regex_'5b'5cd'5d'5b'5cd'5d'2a'28'5c'2e'28'3f'21'5c'2e'29'5b'5cd'5d'2a'28'5beE'5d'5b'2d'2b'5d'3f'5b'5cd'5d'2b'29'3f'29 >>= withAttribute FloatTok) >>~ (popContext)) <|> ((pRegExpr regex_'5c'2e'5b'5cd'5d'5b'5cd'5d'2a'28'5beE'5d'5b'2d'2b'5d'3f'5b'5cd'5d'2b'29'3f >>= withAttribute FloatTok) >>~ (popContext)) <|> ((pRegExpr regex_0'5bxX'5d'5b'5cda'2dfA'2dF'5d'2b >>= withAttribute BaseNTok) >>~ (popContext)) <|> ((pRegExpr regex_'5cd'2b >>= withAttribute DecValTok) >>~ (popContext))) parseRules "ModuleName" = (((pDetect2Chars False '/' '/' >>= withAttribute CommentTok) >>~ pushContext "CommentLine") <|> ((pDetect2Chars False '/' '*' >>= withAttribute CommentTok) >>~ pushContext "CommentBlock") <|> ((pRegExpr regex_'5b'5e'5cs'5cw'2e'3a'2c'5d >>= withAttribute NormalTok) >>~ (popContext))) parseRules "RawString" = ((pDetectChar False '\'' >>= withAttribute StringTok) >>~ (popContext)) parseRules "String" = (((pDetect2Chars False '\\' '"' >>= withAttribute StringTok)) <|> ((pDetectChar False '"' >>= withAttribute StringTok) >>~ (popContext)) <|> ((pHlCStringChar >>= withAttribute StringTok)) <|> ((pRegExpr regex_'5c'5c'28u'5b'5cda'2dfA'2dF'5d'7b4'7d'7cU'5b'5cda'2dfA'2dF'5d'7b8'7d'7c'26'5ba'2dzA'2dZ'5d'5cw'2b'3b'29 >>= withAttribute StringTok))) parseRules "CommentLine" = pzero parseRules "CommentBlock" = ((pDetect2Chars False '*' '/' >>= withAttribute CommentTok) >>~ (popContext)) parseRules "" = parseRules "normal" parseRules x = fail $ "Unknown context" ++ x