Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
typoscript.py217 linesDownload Raw Back to lexers
1"""2    pygments.lexers.typoscript3    ~~~~~~~~~~~~~~~~~~~~~~~~~~4 5    Lexers for TypoScript6 7    `TypoScriptLexer`8        A TypoScript lexer.9 10    `TypoScriptCssDataLexer`11        Lexer that highlights markers, constants and registers within css.12 13    `TypoScriptHtmlDataLexer`14        Lexer that highlights markers, constants and registers within html tags.15 16    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.17    :license: BSD, see LICENSE for details.18"""19 20import re21 22from pygments.lexer import RegexLexer, include, bygroups, using23from pygments.token import Text, Comment, Name, String, Number, \24    Operator, Punctuation25 26__all__ = ['TypoScriptLexer', 'TypoScriptCssDataLexer', 'TypoScriptHtmlDataLexer']27 28 29class TypoScriptCssDataLexer(RegexLexer):30    """31    Lexer that highlights markers, constants and registers within css blocks.32    """33 34    name = 'TypoScriptCssData'35    aliases = ['typoscriptcssdata']36    url = 'http://docs.typo3.org/typo3cms/TyposcriptReference/'37    version_added = '2.2'38 39    tokens = {40        'root': [41            # marker: ###MARK###42            (r'(.*)(###\w+###)(.*)', bygroups(String, Name.Constant, String)),43            # constant: {$some.constant}44            (r'(\{)(\$)((?:[\w\-]+\.)*)([\w\-]+)(\})',45             bygroups(String.Symbol, Operator, Name.Constant,46                      Name.Constant, String.Symbol)),  # constant47            # constant: {register:somevalue}48            (r'(.*)(\{)([\w\-]+)(\s*:\s*)([\w\-]+)(\})(.*)',49             bygroups(String, String.Symbol, Name.Constant, Operator,50                      Name.Constant, String.Symbol, String)),  # constant51            # whitespace52            (r'\s+', Text),53            # comments54            (r'/\*(?:(?!\*/).)*\*/', Comment),55            (r'(?<!(#|\'|"))(?:#(?!(?:[a-fA-F0-9]{6}|[a-fA-F0-9]{3}))[^\n#]+|//[^\n]*)',56             Comment),57            # other58            (r'[<>,:=.*%+|]', String),59            (r'[\w"\-!/&;(){}]+', String),60        ]61    }62 63 64class TypoScriptHtmlDataLexer(RegexLexer):65    """66    Lexer that highlights markers, constants and registers within html tags.67    """68 69    name = 'TypoScriptHtmlData'70    aliases = ['typoscripthtmldata']71    url = 'http://docs.typo3.org/typo3cms/TyposcriptReference/'72    version_added = '2.2'73 74    tokens = {75        'root': [76            # INCLUDE_TYPOSCRIPT77            (r'(INCLUDE_TYPOSCRIPT)', Name.Class),78            # Language label or extension resource FILE:... or LLL:... or EXT:...79            (r'(EXT|FILE|LLL):[^}\n"]*', String),80            # marker: ###MARK###81            (r'(.*)(###\w+###)(.*)', bygroups(String, Name.Constant, String)),82            # constant: {$some.constant}83            (r'(\{)(\$)((?:[\w\-]+\.)*)([\w\-]+)(\})',84             bygroups(String.Symbol, Operator, Name.Constant,85                      Name.Constant, String.Symbol)),  # constant86            # constant: {register:somevalue}87            (r'(.*)(\{)([\w\-]+)(\s*:\s*)([\w\-]+)(\})(.*)',88             bygroups(String, String.Symbol, Name.Constant, Operator,89                      Name.Constant, String.Symbol, String)),  # constant90            # whitespace91            (r'\s+', Text),92            # other93            (r'[<>,:=.*%+|]', String),94            (r'[\w"\-!/&;(){}#]+', String),95        ]96    }97 98 99class TypoScriptLexer(RegexLexer):100    """101    Lexer for TypoScript code.102    """103 104    name = 'TypoScript'105    url = 'http://docs.typo3.org/typo3cms/TyposcriptReference/'106    aliases = ['typoscript']107    filenames = ['*.typoscript']108    mimetypes = ['text/x-typoscript']109    version_added = '2.2'110 111    flags = re.DOTALL | re.MULTILINE112 113    tokens = {114        'root': [115            include('comment'),116            include('constant'),117            include('html'),118            include('label'),119            include('whitespace'),120            include('keywords'),121            include('punctuation'),122            include('operator'),123            include('structure'),124            include('literal'),125            include('other'),126        ],127        'keywords': [128            # Conditions129            (r'(?i)(\[)(browser|compatVersion|dayofmonth|dayofweek|dayofyear|'130             r'device|ELSE|END|GLOBAL|globalString|globalVar|hostname|hour|IP|'131             r'language|loginUser|loginuser|minute|month|page|PIDinRootline|'132             r'PIDupinRootline|system|treeLevel|useragent|userFunc|usergroup|'133             r'version)([^\]]*)(\])',134             bygroups(String.Symbol, Name.Constant, Text, String.Symbol)),135            # Functions136            (r'(?=[\w\-])(HTMLparser|HTMLparser_tags|addParams|cache|encapsLines|'137             r'filelink|if|imageLinkWrap|imgResource|makelinks|numRows|numberFormat|'138             r'parseFunc|replacement|round|select|split|stdWrap|strPad|tableStyle|'139             r'tags|textStyle|typolink)(?![\w\-])', Name.Function),140            # Toplevel objects and _*141            (r'(?:(=?\s*<?\s+|^\s*))(cObj|field|config|content|constants|FEData|'142             r'file|frameset|includeLibs|lib|page|plugin|register|resources|sitemap|'143             r'sitetitle|styles|temp|tt_[^:.\s]*|types|xmlnews|INCLUDE_TYPOSCRIPT|'144             r'_CSS_DEFAULT_STYLE|_DEFAULT_PI_VARS|_LOCAL_LANG)(?![\w\-])',145             bygroups(Operator, Name.Builtin)),146            # Content objects147            (r'(?=[\w\-])(CASE|CLEARGIF|COA|COA_INT|COBJ_ARRAY|COLUMNS|CONTENT|'148             r'CTABLE|EDITPANEL|FILE|FILES|FLUIDTEMPLATE|FORM|HMENU|HRULER|HTML|'149             r'IMAGE|IMGTEXT|IMG_RESOURCE|LOAD_REGISTER|MEDIA|MULTIMEDIA|OTABLE|'150             r'PAGE|QTOBJECT|RECORDS|RESTORE_REGISTER|SEARCHRESULT|SVG|SWFOBJECT|'151             r'TEMPLATE|TEXT|USER|USER_INT)(?![\w\-])', Name.Class),152            # Menu states153            (r'(?=[\w\-])(ACTIFSUBRO|ACTIFSUB|ACTRO|ACT|CURIFSUBRO|CURIFSUB|CURRO|'154             r'CUR|IFSUBRO|IFSUB|NO|SPC|USERDEF1RO|USERDEF1|USERDEF2RO|USERDEF2|'155             r'USRRO|USR)', Name.Class),156            # Menu objects157            (r'(?=[\w\-])(GMENU_FOLDOUT|GMENU_LAYERS|GMENU|IMGMENUITEM|IMGMENU|'158             r'JSMENUITEM|JSMENU|TMENUITEM|TMENU_LAYERS|TMENU)', Name.Class),159            # PHP objects160            (r'(?=[\w\-])(PHP_SCRIPT(_EXT|_INT)?)', Name.Class),161            (r'(?=[\w\-])(userFunc)(?![\w\-])', Name.Function),162        ],163        'whitespace': [164            (r'\s+', Text),165        ],166        'html': [167            (r'<\S[^\n>]*>', using(TypoScriptHtmlDataLexer)),168            (r'&[^;\n]*;', String),169            (r'(?s)(_CSS_DEFAULT_STYLE)(\s*)(\()(.*(?=\n\)))',170             bygroups(Name.Class, Text, String.Symbol, using(TypoScriptCssDataLexer))),171        ],172        'literal': [173            (r'0x[0-9A-Fa-f]+t?', Number.Hex),174            # (r'[0-9]*\.[0-9]+([eE][0-9]+)?[fd]?\s*(?:[^=])', Number.Float),175            (r'[0-9]+', Number.Integer),176            (r'(###\w+###)', Name.Constant),177        ],178        'label': [179            # Language label or extension resource FILE:... or LLL:... or EXT:...180            (r'(EXT|FILE|LLL):[^}\n"]*', String),181            # Path to a resource182            (r'(?![^\w\-])([\w\-]+(?:/[\w\-]+)+/?)(\S*\n)',183             bygroups(String, String)),184        ],185        'punctuation': [186            (r'[,.]', Punctuation),187        ],188        'operator': [189            (r'[<>,:=.*%+|]', Operator),190        ],191        'structure': [192            # Brackets and braces193            (r'[{}()\[\]\\]', String.Symbol),194        ],195        'constant': [196            # Constant: {$some.constant}197            (r'(\{)(\$)((?:[\w\-]+\.)*)([\w\-]+)(\})',198                bygroups(String.Symbol, Operator, Name.Constant,199                         Name.Constant, String.Symbol)),  # constant200            # Constant: {register:somevalue}201            (r'(\{)([\w\-]+)(\s*:\s*)([\w\-]+)(\})',202                bygroups(String.Symbol, Name.Constant, Operator,203                         Name.Constant, String.Symbol)),  # constant204            # Hex color: #ff0077205            (r'(#[a-fA-F0-9]{6}\b|#[a-fA-F0-9]{3}\b)', String.Char)206        ],207        'comment': [208            (r'(?<!(#|\'|"))(?:#(?!(?:[a-fA-F0-9]{6}|[a-fA-F0-9]{3}))[^\n#]+|//[^\n]*)',209             Comment),210            (r'/\*(?:(?!\*/).)*\*/', Comment),211            (r'(\s*#\s*\n)', Comment),212        ],213        'other': [214            (r'[\w"\-!/&;]+', Text),215        ],216    }217 
codekingpro/portable-devtools · Team Ai