1 package lexers
2
3 import (
4 . "github.com/alecthomas/chroma/v2"
5 )
6
7
8 var Typoscript = Register(MustNewLexer(
9 &Config{
10 Name: "TypoScript",
11 Aliases: []string{"typoscript"},
12 Filenames: []string{"*.ts"},
13 MimeTypes: []string{"text/x-typoscript"},
14 DotAll: true,
15 Priority: 0.1,
16 },
17 typoscriptRules,
18 ))
19
20 func typoscriptRules() Rules {
21 return Rules{
22 "root": {
23 Include("comment"),
24 Include("constant"),
25 Include("html"),
26 Include("label"),
27 Include("whitespace"),
28 Include("keywords"),
29 Include("punctuation"),
30 Include("operator"),
31 Include("structure"),
32 Include("literal"),
33 Include("other"),
34 },
35 "keywords": {
36 {`(\[)(?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},
37 {`(?=[\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},
38 {`(?:(=?\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},
39 {`(?=[\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},
40 {`(?=[\w\-])(ACTIFSUBRO|ACTIFSUB|ACTRO|ACT|CURIFSUBRO|CURIFSUB|CURRO|CUR|IFSUBRO|IFSUB|NO|SPC|USERDEF1RO|USERDEF1|USERDEF2RO|USERDEF2|USRRO|USR)`, NameClass, nil},
41 {`(?=[\w\-])(GMENU_FOLDOUT|GMENU_LAYERS|GMENU|IMGMENUITEM|IMGMENU|JSMENUITEM|JSMENU|TMENUITEM|TMENU_LAYERS|TMENU)`, NameClass, nil},
42 {`(?=[\w\-])(PHP_SCRIPT(_EXT|_INT)?)`, NameClass, nil},
43 {`(?=[\w\-])(userFunc)(?![\w\-])`, NameFunction, nil},
44 },
45 "whitespace": {
46 {`\s+`, Text, nil},
47 },
48 "html": {
49 {`<\S[^\n>]*>`, Using("TypoScriptHTMLData"), nil},
50 {`&[^;\n]*;`, LiteralString, nil},
51 {`(_CSS_DEFAULT_STYLE)(\s*)(\()(?s)(.*(?=\n\)))`, ByGroups(NameClass, Text, LiteralStringSymbol, Using("TypoScriptCSSData")), nil},
52 },
53 "literal": {
54 {`0x[0-9A-Fa-f]+t?`, LiteralNumberHex, nil},
55 {`[0-9]+`, LiteralNumberInteger, nil},
56 {`(###\w+###)`, NameConstant, nil},
57 },
58 "label": {
59 {`(EXT|FILE|LLL):[^}\n"]*`, LiteralString, nil},
60 {`(?![^\w\-])([\w\-]+(?:/[\w\-]+)+/?)(\S*\n)`, ByGroups(LiteralString, LiteralString), nil},
61 },
62 "punctuation": {
63 {`[,.]`, Punctuation, nil},
64 },
65 "operator": {
66 {`[<>,:=.*%+|]`, Operator, nil},
67 },
68 "structure": {
69 {`[{}()\[\]\\]`, LiteralStringSymbol, nil},
70 },
71 "constant": {
72 {`(\{)(\$)((?:[\w\-]+\.)*)([\w\-]+)(\})`, ByGroups(LiteralStringSymbol, Operator, NameConstant, NameConstant, LiteralStringSymbol), nil},
73 {`(\{)([\w\-]+)(\s*:\s*)([\w\-]+)(\})`, ByGroups(LiteralStringSymbol, NameConstant, Operator, NameConstant, LiteralStringSymbol), nil},
74 {`(#[a-fA-F0-9]{6}\b|#[a-fA-F0-9]{3}\b)`, LiteralStringChar, nil},
75 },
76 "comment": {
77 {`(?<!(#|\'|"))(?:#(?!(?:[a-fA-F0-9]{6}|[a-fA-F0-9]{3}))[^\n#]+|//[^\n]*)`, Comment, nil},
78 {`/\*(?:(?!\*/).)*\*/`, Comment, nil},
79 {`(\s*#\s*\n)`, Comment, nil},
80 },
81 "other": {
82 {`[\w"\-!/&;]+`, Text, nil},
83 },
84 }
85 }
86
View as plain text