...

Source file src/github.com/alecthomas/chroma/lexers/t/typoscript.go

Documentation: github.com/alecthomas/chroma/lexers/t

     1  package t
     2  
     3  import (
     4  	. "github.com/alecthomas/chroma" // nolint
     5  	"github.com/alecthomas/chroma/lexers/internal"
     6  )
     7  
     8  // Typoscript lexer.
     9  var Typoscript = internal.Register(MustNewLazyLexer(
    10  	&Config{
    11  		Name:      "TypoScript",
    12  		Aliases:   []string{"typoscript"},
    13  		Filenames: []string{"*.ts"},
    14  		MimeTypes: []string{"text/x-typoscript"},
    15  		DotAll:    true,
    16  		Priority:  0.1,
    17  	},
    18  	typoscriptRules,
    19  ))
    20  
    21  func typoscriptRules() Rules {
    22  	return Rules{
    23  		"root": {
    24  			Include("comment"),
    25  			Include("constant"),
    26  			Include("html"),
    27  			Include("label"),
    28  			Include("whitespace"),
    29  			Include("keywords"),
    30  			Include("punctuation"),
    31  			Include("operator"),
    32  			Include("structure"),
    33  			Include("literal"),
    34  			Include("other"),
    35  		},
    36  		"keywords": {
    37  			{`(\[)(?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},
    38  			{`(?=[\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},
    39  			{`(?:(=?\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},
    40  			{`(?=[\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},
    41  			{`(?=[\w\-])(ACTIFSUBRO|ACTIFSUB|ACTRO|ACT|CURIFSUBRO|CURIFSUB|CURRO|CUR|IFSUBRO|IFSUB|NO|SPC|USERDEF1RO|USERDEF1|USERDEF2RO|USERDEF2|USRRO|USR)`, NameClass, nil},
    42  			{`(?=[\w\-])(GMENU_FOLDOUT|GMENU_LAYERS|GMENU|IMGMENUITEM|IMGMENU|JSMENUITEM|JSMENU|TMENUITEM|TMENU_LAYERS|TMENU)`, NameClass, nil},
    43  			{`(?=[\w\-])(PHP_SCRIPT(_EXT|_INT)?)`, NameClass, nil},
    44  			{`(?=[\w\-])(userFunc)(?![\w\-])`, NameFunction, nil},
    45  		},
    46  		"whitespace": {
    47  			{`\s+`, Text, nil},
    48  		},
    49  		"html": {
    50  			{`<\S[^\n>]*>`, Using(TypoScriptHTMLData), nil},
    51  			{`&[^;\n]*;`, LiteralString, nil},
    52  			{`(_CSS_DEFAULT_STYLE)(\s*)(\()(?s)(.*(?=\n\)))`, ByGroups(NameClass, Text, LiteralStringSymbol, Using(TypoScriptCSSData)), nil},
    53  		},
    54  		"literal": {
    55  			{`0x[0-9A-Fa-f]+t?`, LiteralNumberHex, nil},
    56  			{`[0-9]+`, LiteralNumberInteger, nil},
    57  			{`(###\w+###)`, NameConstant, nil},
    58  		},
    59  		"label": {
    60  			{`(EXT|FILE|LLL):[^}\n"]*`, LiteralString, nil},
    61  			{`(?![^\w\-])([\w\-]+(?:/[\w\-]+)+/?)(\S*\n)`, ByGroups(LiteralString, LiteralString), nil},
    62  		},
    63  		"punctuation": {
    64  			{`[,.]`, Punctuation, nil},
    65  		},
    66  		"operator": {
    67  			{`[<>,:=.*%+|]`, Operator, nil},
    68  		},
    69  		"structure": {
    70  			{`[{}()\[\]\\]`, LiteralStringSymbol, nil},
    71  		},
    72  		"constant": {
    73  			{`(\{)(\$)((?:[\w\-]+\.)*)([\w\-]+)(\})`, ByGroups(LiteralStringSymbol, Operator, NameConstant, NameConstant, LiteralStringSymbol), nil},
    74  			{`(\{)([\w\-]+)(\s*:\s*)([\w\-]+)(\})`, ByGroups(LiteralStringSymbol, NameConstant, Operator, NameConstant, LiteralStringSymbol), nil},
    75  			{`(#[a-fA-F0-9]{6}\b|#[a-fA-F0-9]{3}\b)`, LiteralStringChar, nil},
    76  		},
    77  		"comment": {
    78  			{`(?<!(#|\'|"))(?:#(?!(?:[a-fA-F0-9]{6}|[a-fA-F0-9]{3}))[^\n#]+|//[^\n]*)`, Comment, nil},
    79  			{`/\*(?:(?!\*/).)*\*/`, Comment, nil},
    80  			{`(\s*#\s*\n)`, Comment, nil},
    81  		},
    82  		"other": {
    83  			{`[\w"\-!/&;]+`, Text, nil},
    84  		},
    85  	}
    86  }
    87  
    88  // TypoScriptCSSData lexer.
    89  var TypoScriptCSSData = internal.Register(MustNewLazyLexer(
    90  	&Config{
    91  		Name:      "TypoScriptCssData",
    92  		Aliases:   []string{"typoscriptcssdata"},
    93  		Filenames: []string{},
    94  		MimeTypes: []string{},
    95  	},
    96  	typoScriptCSSDataRules,
    97  ))
    98  
    99  func typoScriptCSSDataRules() Rules {
   100  	return Rules{
   101  		"root": {
   102  			{`(.*)(###\w+###)(.*)`, ByGroups(LiteralString, NameConstant, LiteralString), nil},
   103  			{`(\{)(\$)((?:[\w\-]+\.)*)([\w\-]+)(\})`, ByGroups(LiteralStringSymbol, Operator, NameConstant, NameConstant, LiteralStringSymbol), nil},
   104  			{`(.*)(\{)([\w\-]+)(\s*:\s*)([\w\-]+)(\})(.*)`, ByGroups(LiteralString, LiteralStringSymbol, NameConstant, Operator, NameConstant, LiteralStringSymbol, LiteralString), nil},
   105  			{`\s+`, Text, nil},
   106  			{`/\*(?:(?!\*/).)*\*/`, Comment, nil},
   107  			{`(?<!(#|\'|"))(?:#(?!(?:[a-fA-F0-9]{6}|[a-fA-F0-9]{3}))[^\n#]+|//[^\n]*)`, Comment, nil},
   108  			{`[<>,:=.*%+|]`, LiteralString, nil},
   109  			{`[\w"\-!/&;(){}]+`, LiteralString, nil},
   110  		},
   111  	}
   112  }
   113  
   114  // TypoScriptHTMLData lexer.
   115  var TypoScriptHTMLData = internal.Register(MustNewLazyLexer(
   116  	&Config{
   117  		Name:      "TypoScriptHtmlData",
   118  		Aliases:   []string{"typoscripthtmldata"},
   119  		Filenames: []string{},
   120  		MimeTypes: []string{},
   121  	},
   122  	typoScriptHTMLDataRules,
   123  ))
   124  
   125  func typoScriptHTMLDataRules() Rules {
   126  	return Rules{
   127  		"root": {
   128  			{`(INCLUDE_TYPOSCRIPT)`, NameClass, nil},
   129  			{`(EXT|FILE|LLL):[^}\n"]*`, LiteralString, nil},
   130  			{`(.*)(###\w+###)(.*)`, ByGroups(LiteralString, NameConstant, LiteralString), nil},
   131  			{`(\{)(\$)((?:[\w\-]+\.)*)([\w\-]+)(\})`, ByGroups(LiteralStringSymbol, Operator, NameConstant, NameConstant, LiteralStringSymbol), nil},
   132  			{`(.*)(\{)([\w\-]+)(\s*:\s*)([\w\-]+)(\})(.*)`, ByGroups(LiteralString, LiteralStringSymbol, NameConstant, Operator, NameConstant, LiteralStringSymbol, LiteralString), nil},
   133  			{`\s+`, Text, nil},
   134  			{`[<>,:=.*%+|]`, LiteralString, nil},
   135  			{`[\w"\-!/&;(){}#]+`, LiteralString, nil},
   136  		},
   137  	}
   138  }
   139  

View as plain text