ThirdParty/Pygments/pygments/lexers/typoscript.py

changeset 5713
6762afd9f963
child 6651
e8f3b5568b21
equal deleted inserted replaced
5712:f0d08bdeacf4 5713:6762afd9f963
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-2017 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 = ['*.ts', '*.txt']
112 mimetypes = ['text/x-typoscript']
113
114 flags = re.DOTALL | re.MULTILINE
115
116 # Slightly higher than TypeScript (which is 0).
117 priority = 0.1
118
119 tokens = {
120 'root': [
121 include('comment'),
122 include('constant'),
123 include('html'),
124 include('label'),
125 include('whitespace'),
126 include('keywords'),
127 include('punctuation'),
128 include('operator'),
129 include('structure'),
130 include('literal'),
131 include('other'),
132 ],
133 'keywords': [
134 # Conditions
135 (r'(\[)(?i)(browser|compatVersion|dayofmonth|dayofweek|dayofyear|'
136 r'device|ELSE|END|GLOBAL|globalString|globalVar|hostname|hour|IP|'
137 r'language|loginUser|loginuser|minute|month|page|PIDinRootline|'
138 r'PIDupinRootline|system|treeLevel|useragent|userFunc|usergroup|'
139 r'version)([^\]]*)(\])',
140 bygroups(String.Symbol, Name.Constant, Text, String.Symbol)),
141 # Functions
142 (r'(?=[\w\-])(HTMLparser|HTMLparser_tags|addParams|cache|encapsLines|'
143 r'filelink|if|imageLinkWrap|imgResource|makelinks|numRows|numberFormat|'
144 r'parseFunc|replacement|round|select|split|stdWrap|strPad|tableStyle|'
145 r'tags|textStyle|typolink)(?![\w\-])', Name.Function),
146 # Toplevel objects and _*
147 (r'(?:(=?\s*<?\s+|^\s*))(cObj|field|config|content|constants|FEData|'
148 r'file|frameset|includeLibs|lib|page|plugin|register|resources|sitemap|'
149 r'sitetitle|styles|temp|tt_[^:.\s]*|types|xmlnews|INCLUDE_TYPOSCRIPT|'
150 r'_CSS_DEFAULT_STYLE|_DEFAULT_PI_VARS|_LOCAL_LANG)(?![\w\-])',
151 bygroups(Operator, Name.Builtin)),
152 # Content objects
153 (r'(?=[\w\-])(CASE|CLEARGIF|COA|COA_INT|COBJ_ARRAY|COLUMNS|CONTENT|'
154 r'CTABLE|EDITPANEL|FILE|FILES|FLUIDTEMPLATE|FORM|HMENU|HRULER|HTML|'
155 r'IMAGE|IMGTEXT|IMG_RESOURCE|LOAD_REGISTER|MEDIA|MULTIMEDIA|OTABLE|'
156 r'PAGE|QTOBJECT|RECORDS|RESTORE_REGISTER|SEARCHRESULT|SVG|SWFOBJECT|'
157 r'TEMPLATE|TEXT|USER|USER_INT)(?![\w\-])', Name.Class),
158 # Menu states
159 (r'(?=[\w\-])(ACTIFSUBRO|ACTIFSUB|ACTRO|ACT|CURIFSUBRO|CURIFSUB|CURRO|'
160 r'CUR|IFSUBRO|IFSUB|NO|SPC|USERDEF1RO|USERDEF1|USERDEF2RO|USERDEF2|'
161 r'USRRO|USR)', Name.Class),
162 # Menu objects
163 (r'(?=[\w\-])(GMENU_FOLDOUT|GMENU_LAYERS|GMENU|IMGMENUITEM|IMGMENU|'
164 r'JSMENUITEM|JSMENU|TMENUITEM|TMENU_LAYERS|TMENU)', Name.Class),
165 # PHP objects
166 (r'(?=[\w\-])(PHP_SCRIPT(_EXT|_INT)?)', Name.Class),
167 (r'(?=[\w\-])(userFunc)(?![\w\-])', Name.Function),
168 ],
169 'whitespace': [
170 (r'\s+', Text),
171 ],
172 'html': [
173 (r'<\S[^\n>]*>', using(TypoScriptHtmlDataLexer)),
174 (r'&[^;\n]*;', String),
175 (r'(_CSS_DEFAULT_STYLE)(\s*)(\()(?s)(.*(?=\n\)))',
176 bygroups(Name.Class, Text, String.Symbol, using(TypoScriptCssDataLexer))),
177 ],
178 'literal': [
179 (r'0x[0-9A-Fa-f]+t?', Number.Hex),
180 # (r'[0-9]*\.[0-9]+([eE][0-9]+)?[fd]?\s*(?:[^=])', Number.Float),
181 (r'[0-9]+', Number.Integer),
182 (r'(###\w+###)', Name.Constant),
183 ],
184 'label': [
185 # Language label or extension resource FILE:... or LLL:... or EXT:...
186 (r'(EXT|FILE|LLL):[^}\n"]*', String),
187 # Path to a resource
188 (r'(?![^\w\-])([\w\-]+(?:/[\w\-]+)+/?)(\S*\n)',
189 bygroups(String, String)),
190 ],
191 'punctuation': [
192 (r'[,.]', Punctuation),
193 ],
194 'operator': [
195 (r'[<>,:=.*%+|]', Operator),
196 ],
197 'structure': [
198 # Brackets and braces
199 (r'[{}()\[\]\\]', String.Symbol),
200 ],
201 'constant': [
202 # Constant: {$some.constant}
203 (r'(\{)(\$)((?:[\w\-]+\.)*)([\w\-]+)(\})',
204 bygroups(String.Symbol, Operator, Name.Constant,
205 Name.Constant, String.Symbol)), # constant
206 # Constant: {register:somevalue}
207 (r'(\{)([\w\-]+)(\s*:\s*)([\w\-]+)(\})',
208 bygroups(String.Symbol, Name.Constant, Operator,
209 Name.Constant, String.Symbol)), # constant
210 # Hex color: #ff0077
211 (r'(#[a-fA-F0-9]{6}\b|#[a-fA-F0-9]{3}\b)', String.Char)
212 ],
213 'comment': [
214 (r'(?<!(#|\'|"))(?:#(?!(?:[a-fA-F0-9]{6}|[a-fA-F0-9]{3}))[^\n#]+|//[^\n]*)',
215 Comment),
216 (r'/\*(?:(?!\*/).)*\*/', Comment),
217 (r'(\s*#\s*\n)', Comment),
218 ],
219 'other': [
220 (r'[\w"\-!/&;]+', Text),
221 ],
222 }
223
224 def analyse_text(text):
225 if '<INCLUDE_TYPOSCRIPT:' in text:
226 return 1.0

eric ide

mercurial