1 package t
2
3 import (
4 . "github.com/alecthomas/chroma"
5 "github.com/alecthomas/chroma/lexers/internal"
6 )
7
8
9 var Tcl = internal.Register(MustNewLazyLexer(
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 tclRules,
17 ))
18
19 func tclRules() Rules {
20 return Rules{
21 "root": {
22 Include("command"),
23 Include("basic"),
24 Include("data"),
25 {`\}`, Keyword, nil},
26 },
27 "command": {
28 {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")},
29 {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")},
30 {`([\w.-]+)`, NameVariable, Push("params")},
31 {`#`, Comment, Push("comment")},
32 },
33 "command-in-brace": {
34 {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")},
35 {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")},
36 {`([\w.-]+)`, NameVariable, Push("params-in-brace")},
37 {`#`, Comment, Push("comment")},
38 },
39 "command-in-bracket": {
40 {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")},
41 {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")},
42 {`([\w.-]+)`, NameVariable, Push("params-in-bracket")},
43 {`#`, Comment, Push("comment")},
44 },
45 "command-in-paren": {
46 {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")},
47 {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")},
48 {`([\w.-]+)`, NameVariable, Push("params-in-paren")},
49 {`#`, Comment, Push("comment")},
50 },
51 "basic": {
52 {`\(`, Keyword, Push("paren")},
53 {`\[`, Keyword, Push("bracket")},
54 {`\{`, Keyword, Push("brace")},
55 {`"`, LiteralStringDouble, Push("string")},
56 {`(eq|ne|in|ni)\b`, OperatorWord, nil},
57 {`!=|==|<<|>>|<=|>=|&&|\|\||\*\*|[-+~!*/%<>&^|?:]`, Operator, nil},
58 },
59 "data": {
60 {`\s+`, Text, nil},
61 {`0x[a-fA-F0-9]+`, LiteralNumberHex, nil},
62 {`0[0-7]+`, LiteralNumberOct, nil},
63 {`\d+\.\d+`, LiteralNumberFloat, nil},
64 {`\d+`, LiteralNumberInteger, nil},
65 {`\$([\w.:-]+)`, NameVariable, nil},
66 {`([\w.:-]+)`, Text, nil},
67 },
68 "params": {
69 {`;`, Keyword, Pop(1)},
70 {`\n`, Text, Pop(1)},
71 {`(else|elseif|then)\b`, Keyword, nil},
72 Include("basic"),
73 Include("data"),
74 },
75 "params-in-brace": {
76 {`\}`, Keyword, Push("#pop", "#pop")},
77 Include("params"),
78 },
79 "params-in-paren": {
80 {`\)`, Keyword, Push("#pop", "#pop")},
81 Include("params"),
82 },
83 "params-in-bracket": {
84 {`\]`, Keyword, Push("#pop", "#pop")},
85 Include("params"),
86 },
87 "string": {
88 {`\[`, LiteralStringDouble, Push("string-square")},
89 {`(?s)(\\\\|\\[0-7]+|\\.|[^"\\])`, LiteralStringDouble, nil},
90 {`"`, LiteralStringDouble, Pop(1)},
91 },
92 "string-square": {
93 {`\[`, LiteralStringDouble, Push("string-square")},
94 {`(?s)(\\\\|\\[0-7]+|\\.|\\\n|[^\]\\])`, LiteralStringDouble, nil},
95 {`\]`, LiteralStringDouble, Pop(1)},
96 },
97 "brace": {
98 {`\}`, Keyword, Pop(1)},
99 Include("command-in-brace"),
100 Include("basic"),
101 Include("data"),
102 },
103 "paren": {
104 {`\)`, Keyword, Pop(1)},
105 Include("command-in-paren"),
106 Include("basic"),
107 Include("data"),
108 },
109 "bracket": {
110 {`\]`, Keyword, Pop(1)},
111 Include("command-in-bracket"),
112 Include("basic"),
113 Include("data"),
114 },
115 "comment": {
116 {`.*[^\\]\n`, Comment, Pop(1)},
117 {`.*\\\n`, Comment, nil},
118 },
119 }
120 }
121
View as plain text