1package t
2
3import (
4 . "github.com/alecthomas/chroma" // nolint
5 "github.com/alecthomas/chroma/lexers/internal"
6)
7
8// Typoscript lexer.
9var Typoscript = internal.Register(MustNewLexer(
10 &Config{
11 Name: "TypoScript",
12 Aliases: []string{"typoscript"},
13 Filenames: []string{"*.ts", "*.txt"},
14 MimeTypes: []string{"text/x-typoscript"},
15 DotAll: true,
16 },
17 Rules{
18 "root": {
19 Include("comment"),
20 Include("constant"),
21 Include("html"),
22 Include("label"),
23 Include("whitespace"),
24 Include("keywords"),
25 Include("punctuation"),
26 Include("operator"),
27 Include("structure"),
28 Include("literal"),
29 Include("other"),
30 },
31 "keywords": {
32 {`(\[)(?i)(browser|compatVersion|dayofmonth|dayofweek|dayofyear|device|ELSE|END|GLOBAL|globalString|globalVar|hostname|hour|IP|language|loginUser|loginuser|minute|month|page|PIDinRootline|PIDupinRootline|system|treeLevel|useragent|userFunc|usergroup|version)([^\]]*)(\])`, ByGroups(LiteralStringSymbol, NameConstant, Text, LiteralStringSymbol), nil},
33 {`(?=[\w\-])(HTMLparser|HTMLparser_tags|addParams|cache|encapsLines|filelink|if|imageLinkWrap|imgResource|makelinks|numRows|numberFormat|parseFunc|replacement|round|select|split|stdWrap|strPad|tableStyle|tags|textStyle|typolink)(?![\w\-])`, NameFunction, nil},
34 {`(?:(=?\s*<?\s+|^\s*))(cObj|field|config|content|constants|FEData|file|frameset|includeLibs|lib|page|plugin|register|resources|sitemap|sitetitle|styles|temp|tt_[^:.\s]*|types|xmlnews|INCLUDE_TYPOSCRIPT|_CSS_DEFAULT_STYLE|_DEFAULT_PI_VARS|_LOCAL_LANG)(?![\w\-])`, ByGroups(Operator, NameBuiltin), nil},
35 {`(?=[\w\-])(CASE|CLEARGIF|COA|COA_INT|COBJ_ARRAY|COLUMNS|CONTENT|CTABLE|EDITPANEL|FILE|FILES|FLUIDTEMPLATE|FORM|HMENU|HRULER|HTML|IMAGE|IMGTEXT|IMG_RESOURCE|LOAD_REGISTER|MEDIA|MULTIMEDIA|OTABLE|PAGE|QTOBJECT|RECORDS|RESTORE_REGISTER|SEARCHRESULT|SVG|SWFOBJECT|TEMPLATE|TEXT|USER|USER_INT)(?![\w\-])`, NameClass, nil},
36 {`(?=[\w\-])(ACTIFSUBRO|ACTIFSUB|ACTRO|ACT|CURIFSUBRO|CURIFSUB|CURRO|CUR|IFSUBRO|IFSUB|NO|SPC|USERDEF1RO|USERDEF1|USERDEF2RO|USERDEF2|USRRO|USR)`, NameClass, nil},
37 {`(?=[\w\-])(GMENU_FOLDOUT|GMENU_LAYERS|GMENU|IMGMENUITEM|IMGMENU|JSMENUITEM|JSMENU|TMENUITEM|TMENU_LAYERS|TMENU)`, NameClass, nil},
38 {`(?=[\w\-])(PHP_SCRIPT(_EXT|_INT)?)`, NameClass, nil},
39 {`(?=[\w\-])(userFunc)(?![\w\-])`, NameFunction, nil},
40 },
41 "whitespace": {
42 {`\s+`, Text, nil},
43 },
44 "html": {
45 {`<\S[^\n>]*>`, Using(TypoScriptHTMLData), nil},
46 {`&[^;\n]*;`, LiteralString, nil},
47 {`(_CSS_DEFAULT_STYLE)(\s*)(\()(?s)(.*(?=\n\)))`, ByGroups(NameClass, Text, LiteralStringSymbol, Using(TypoScriptCSSData)), nil},
48 },
49 "literal": {
50 {`0x[0-9A-Fa-f]+t?`, LiteralNumberHex, nil},
51 {`[0-9]+`, LiteralNumberInteger, nil},
52 {`(###\w+###)`, NameConstant, nil},
53 },
54 "label": {
55 {`(EXT|FILE|LLL):[^}\n"]*`, LiteralString, nil},
56 {`(?![^\w\-])([\w\-]+(?:/[\w\-]+)+/?)(\S*\n)`, ByGroups(LiteralString, LiteralString), nil},
57 },
58 "punctuation": {
59 {`[,.]`, Punctuation, nil},
60 },
61 "operator": {
62 {`[<>,:=.*%+|]`, Operator, nil},
63 },
64 "structure": {
65 {`[{}()\[\]\\]`, LiteralStringSymbol, nil},
66 },
67 "constant": {
68 {`(\{)(\$)((?:[\w\-]+\.)*)([\w\-]+)(\})`, ByGroups(LiteralStringSymbol, Operator, NameConstant, NameConstant, LiteralStringSymbol), nil},
69 {`(\{)([\w\-]+)(\s*:\s*)([\w\-]+)(\})`, ByGroups(LiteralStringSymbol, NameConstant, Operator, NameConstant, LiteralStringSymbol), nil},
70 {`(#[a-fA-F0-9]{6}\b|#[a-fA-F0-9]{3}\b)`, LiteralStringChar, nil},
71 },
72 "comment": {
73 {`(?<!(#|\'|"))(?:#(?!(?:[a-fA-F0-9]{6}|[a-fA-F0-9]{3}))[^\n#]+|//[^\n]*)`, Comment, nil},
74 {`/\*(?:(?!\*/).)*\*/`, Comment, nil},
75 {`(\s*#\s*\n)`, Comment, nil},
76 },
77 "other": {
78 {`[\w"\-!/&;]+`, Text, nil},
79 },
80 },
81))
82
83// TypoScriptCSSData lexer.
84var TypoScriptCSSData = internal.Register(MustNewLexer(
85 &Config{
86 Name: "TypoScriptCssData",
87 Aliases: []string{"typoscriptcssdata"},
88 Filenames: []string{},
89 MimeTypes: []string{},
90 },
91 Rules{
92 "root": {
93 {`(.*)(###\w+###)(.*)`, ByGroups(LiteralString, NameConstant, LiteralString), nil},
94 {`(\{)(\$)((?:[\w\-]+\.)*)([\w\-]+)(\})`, ByGroups(LiteralStringSymbol, Operator, NameConstant, NameConstant, LiteralStringSymbol), nil},
95 {`(.*)(\{)([\w\-]+)(\s*:\s*)([\w\-]+)(\})(.*)`, ByGroups(LiteralString, LiteralStringSymbol, NameConstant, Operator, NameConstant, LiteralStringSymbol, LiteralString), nil},
96 {`\s+`, Text, nil},
97 {`/\*(?:(?!\*/).)*\*/`, Comment, nil},
98 {`(?<!(#|\'|"))(?:#(?!(?:[a-fA-F0-9]{6}|[a-fA-F0-9]{3}))[^\n#]+|//[^\n]*)`, Comment, nil},
99 {`[<>,:=.*%+|]`, LiteralString, nil},
100 {`[\w"\-!/&;(){}]+`, LiteralString, nil},
101 },
102 },
103))
104
105// TypoScriptHTMLData lexer.
106var TypoScriptHTMLData = internal.Register(MustNewLexer(
107 &Config{
108 Name: "TypoScriptHtmlData",
109 Aliases: []string{"typoscripthtmldata"},
110 Filenames: []string{},
111 MimeTypes: []string{},
112 },
113 Rules{
114 "root": {
115 {`(INCLUDE_TYPOSCRIPT)`, NameClass, nil},
116 {`(EXT|FILE|LLL):[^}\n"]*`, LiteralString, nil},
117 {`(.*)(###\w+###)(.*)`, ByGroups(LiteralString, NameConstant, LiteralString), nil},
118 {`(\{)(\$)((?:[\w\-]+\.)*)([\w\-]+)(\})`, ByGroups(LiteralStringSymbol, Operator, NameConstant, NameConstant, LiteralStringSymbol), nil},
119 {`(.*)(\{)([\w\-]+)(\s*:\s*)([\w\-]+)(\})(.*)`, ByGroups(LiteralString, LiteralStringSymbol, NameConstant, Operator, NameConstant, LiteralStringSymbol, LiteralString), nil},
120 {`\s+`, Text, nil},
121 {`[<>,:=.*%+|]`, LiteralString, nil},
122 {`[\w"\-!/&;(){}#]+`, LiteralString, nil},
123 },
124 },
125))