eric6/ThirdParty/Pygments/pygments/lexers/typoscript.py

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

eric ide

mercurial