tcl.go

  1package t
  2
  3import (
  4	. "github.com/alecthomas/chroma" // nolint
  5	"github.com/alecthomas/chroma/lexers/internal"
  6)
  7
  8// Tcl lexer.
  9var Tcl = internal.Register(MustNewLexer(
 10	&Config{
 11		Name:      "Tcl",
 12		Aliases:   []string{"tcl"},
 13		Filenames: []string{"*.tcl", "*.rvt"},
 14		MimeTypes: []string{"text/x-tcl", "text/x-script.tcl", "application/x-tcl"},
 15	},
 16	Rules{
 17		"root": {
 18			Include("command"),
 19			Include("basic"),
 20			Include("data"),
 21			{`\}`, Keyword, nil},
 22		},
 23		"command": {
 24			{Words(`\b`, `\b`, `after`, `apply`, `array`, `break`, `catch`, `continue`, `elseif`, `else`, `error`, `eval`, `expr`, `for`, `foreach`, `global`, `if`, `namespace`, `proc`, `rename`, `return`, `set`, `switch`, `then`, `trace`, `unset`, `update`, `uplevel`, `upvar`, `variable`, `vwait`, `while`), Keyword, Push("params")},
 25			{Words(`\b`, `\b`, `append`, `bgerror`, `binary`, `cd`, `chan`, `clock`, `close`, `concat`, `dde`, `dict`, `encoding`, `eof`, `exec`, `exit`, `fblocked`, `fconfigure`, `fcopy`, `file`, `fileevent`, `flush`, `format`, `gets`, `glob`, `history`, `http`, `incr`, `info`, `interp`, `join`, `lappend`, `lassign`, `lindex`, `linsert`, `list`, `llength`, `load`, `loadTk`, `lrange`, `lrepeat`, `lreplace`, `lreverse`, `lsearch`, `lset`, `lsort`, `mathfunc`, `mathop`, `memory`, `msgcat`, `open`, `package`, `pid`, `pkg::create`, `pkg_mkIndex`, `platform`, `platform::shell`, `puts`, `pwd`, `re_syntax`, `read`, `refchan`, `regexp`, `registry`, `regsub`, `scan`, `seek`, `socket`, `source`, `split`, `string`, `subst`, `tell`, `time`, `tm`, `unknown`, `unload`), NameBuiltin, Push("params")},
 26			{`([\w.-]+)`, NameVariable, Push("params")},
 27			{`#`, Comment, Push("comment")},
 28		},
 29		"command-in-brace": {
 30			{Words(`\b`, `\b`, `after`, `apply`, `array`, `break`, `catch`, `continue`, `elseif`, `else`, `error`, `eval`, `expr`, `for`, `foreach`, `global`, `if`, `namespace`, `proc`, `rename`, `return`, `set`, `switch`, `then`, `trace`, `unset`, `update`, `uplevel`, `upvar`, `variable`, `vwait`, `while`), Keyword, Push("params-in-brace")},
 31			{Words(`\b`, `\b`, `append`, `bgerror`, `binary`, `cd`, `chan`, `clock`, `close`, `concat`, `dde`, `dict`, `encoding`, `eof`, `exec`, `exit`, `fblocked`, `fconfigure`, `fcopy`, `file`, `fileevent`, `flush`, `format`, `gets`, `glob`, `history`, `http`, `incr`, `info`, `interp`, `join`, `lappend`, `lassign`, `lindex`, `linsert`, `list`, `llength`, `load`, `loadTk`, `lrange`, `lrepeat`, `lreplace`, `lreverse`, `lsearch`, `lset`, `lsort`, `mathfunc`, `mathop`, `memory`, `msgcat`, `open`, `package`, `pid`, `pkg::create`, `pkg_mkIndex`, `platform`, `platform::shell`, `puts`, `pwd`, `re_syntax`, `read`, `refchan`, `regexp`, `registry`, `regsub`, `scan`, `seek`, `socket`, `source`, `split`, `string`, `subst`, `tell`, `time`, `tm`, `unknown`, `unload`), NameBuiltin, Push("params-in-brace")},
 32			{`([\w.-]+)`, NameVariable, Push("params-in-brace")},
 33			{`#`, Comment, Push("comment")},
 34		},
 35		"command-in-bracket": {
 36			{Words(`\b`, `\b`, `after`, `apply`, `array`, `break`, `catch`, `continue`, `elseif`, `else`, `error`, `eval`, `expr`, `for`, `foreach`, `global`, `if`, `namespace`, `proc`, `rename`, `return`, `set`, `switch`, `then`, `trace`, `unset`, `update`, `uplevel`, `upvar`, `variable`, `vwait`, `while`), Keyword, Push("params-in-bracket")},
 37			{Words(`\b`, `\b`, `append`, `bgerror`, `binary`, `cd`, `chan`, `clock`, `close`, `concat`, `dde`, `dict`, `encoding`, `eof`, `exec`, `exit`, `fblocked`, `fconfigure`, `fcopy`, `file`, `fileevent`, `flush`, `format`, `gets`, `glob`, `history`, `http`, `incr`, `info`, `interp`, `join`, `lappend`, `lassign`, `lindex`, `linsert`, `list`, `llength`, `load`, `loadTk`, `lrange`, `lrepeat`, `lreplace`, `lreverse`, `lsearch`, `lset`, `lsort`, `mathfunc`, `mathop`, `memory`, `msgcat`, `open`, `package`, `pid`, `pkg::create`, `pkg_mkIndex`, `platform`, `platform::shell`, `puts`, `pwd`, `re_syntax`, `read`, `refchan`, `regexp`, `registry`, `regsub`, `scan`, `seek`, `socket`, `source`, `split`, `string`, `subst`, `tell`, `time`, `tm`, `unknown`, `unload`), NameBuiltin, Push("params-in-bracket")},
 38			{`([\w.-]+)`, NameVariable, Push("params-in-bracket")},
 39			{`#`, Comment, Push("comment")},
 40		},
 41		"command-in-paren": {
 42			{Words(`\b`, `\b`, `after`, `apply`, `array`, `break`, `catch`, `continue`, `elseif`, `else`, `error`, `eval`, `expr`, `for`, `foreach`, `global`, `if`, `namespace`, `proc`, `rename`, `return`, `set`, `switch`, `then`, `trace`, `unset`, `update`, `uplevel`, `upvar`, `variable`, `vwait`, `while`), Keyword, Push("params-in-paren")},
 43			{Words(`\b`, `\b`, `append`, `bgerror`, `binary`, `cd`, `chan`, `clock`, `close`, `concat`, `dde`, `dict`, `encoding`, `eof`, `exec`, `exit`, `fblocked`, `fconfigure`, `fcopy`, `file`, `fileevent`, `flush`, `format`, `gets`, `glob`, `history`, `http`, `incr`, `info`, `interp`, `join`, `lappend`, `lassign`, `lindex`, `linsert`, `list`, `llength`, `load`, `loadTk`, `lrange`, `lrepeat`, `lreplace`, `lreverse`, `lsearch`, `lset`, `lsort`, `mathfunc`, `mathop`, `memory`, `msgcat`, `open`, `package`, `pid`, `pkg::create`, `pkg_mkIndex`, `platform`, `platform::shell`, `puts`, `pwd`, `re_syntax`, `read`, `refchan`, `regexp`, `registry`, `regsub`, `scan`, `seek`, `socket`, `source`, `split`, `string`, `subst`, `tell`, `time`, `tm`, `unknown`, `unload`), NameBuiltin, Push("params-in-paren")},
 44			{`([\w.-]+)`, NameVariable, Push("params-in-paren")},
 45			{`#`, Comment, Push("comment")},
 46		},
 47		"basic": {
 48			{`\(`, Keyword, Push("paren")},
 49			{`\[`, Keyword, Push("bracket")},
 50			{`\{`, Keyword, Push("brace")},
 51			{`"`, LiteralStringDouble, Push("string")},
 52			{`(eq|ne|in|ni)\b`, OperatorWord, nil},
 53			{`!=|==|<<|>>|<=|>=|&&|\|\||\*\*|[-+~!*/%<>&^|?:]`, Operator, nil},
 54		},
 55		"data": {
 56			{`\s+`, Text, nil},
 57			{`0x[a-fA-F0-9]+`, LiteralNumberHex, nil},
 58			{`0[0-7]+`, LiteralNumberOct, nil},
 59			{`\d+\.\d+`, LiteralNumberFloat, nil},
 60			{`\d+`, LiteralNumberInteger, nil},
 61			{`\$([\w.:-]+)`, NameVariable, nil},
 62			{`([\w.:-]+)`, Text, nil},
 63		},
 64		"params": {
 65			{`;`, Keyword, Pop(1)},
 66			{`\n`, Text, Pop(1)},
 67			{`(else|elseif|then)\b`, Keyword, nil},
 68			Include("basic"),
 69			Include("data"),
 70		},
 71		"params-in-brace": {
 72			{`\}`, Keyword, Push("#pop", "#pop")},
 73			Include("params"),
 74		},
 75		"params-in-paren": {
 76			{`\)`, Keyword, Push("#pop", "#pop")},
 77			Include("params"),
 78		},
 79		"params-in-bracket": {
 80			{`\]`, Keyword, Push("#pop", "#pop")},
 81			Include("params"),
 82		},
 83		"string": {
 84			{`\[`, LiteralStringDouble, Push("string-square")},
 85			{`(?s)(\\\\|\\[0-7]+|\\.|[^"\\])`, LiteralStringDouble, nil},
 86			{`"`, LiteralStringDouble, Pop(1)},
 87		},
 88		"string-square": {
 89			{`\[`, LiteralStringDouble, Push("string-square")},
 90			{`(?s)(\\\\|\\[0-7]+|\\.|\\\n|[^\]\\])`, LiteralStringDouble, nil},
 91			{`\]`, LiteralStringDouble, Pop(1)},
 92		},
 93		"brace": {
 94			{`\}`, Keyword, Pop(1)},
 95			Include("command-in-brace"),
 96			Include("basic"),
 97			Include("data"),
 98		},
 99		"paren": {
100			{`\)`, Keyword, Pop(1)},
101			Include("command-in-paren"),
102			Include("basic"),
103			Include("data"),
104		},
105		"bracket": {
106			{`\]`, Keyword, Pop(1)},
107			Include("command-in-bracket"),
108			Include("basic"),
109			Include("data"),
110		},
111		"comment": {
112			{`.*[^\\]\n`, Comment, Pop(1)},
113			{`.*\\\n`, Comment, nil},
114		},
115	},
116))