typoscript.py 8.0 KB

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