typoscript.py 8.0 KB

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