tcl.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. Language: Tcl
  3. Description: Tcl is a very simple programming language.
  4. Author: Radek Liska <radekliska@gmail.com>
  5. Website: https://www.tcl.tk/about/language.html
  6. Category: scripting
  7. */
  8. function tcl(hljs) {
  9. const regex = hljs.regex;
  10. const TCL_IDENT = /[a-zA-Z_][a-zA-Z0-9_]*/;
  11. const NUMBER = {
  12. className: 'number',
  13. variants: [
  14. hljs.BINARY_NUMBER_MODE,
  15. hljs.C_NUMBER_MODE
  16. ]
  17. };
  18. const KEYWORDS = [
  19. "after",
  20. "append",
  21. "apply",
  22. "array",
  23. "auto_execok",
  24. "auto_import",
  25. "auto_load",
  26. "auto_mkindex",
  27. "auto_mkindex_old",
  28. "auto_qualify",
  29. "auto_reset",
  30. "bgerror",
  31. "binary",
  32. "break",
  33. "catch",
  34. "cd",
  35. "chan",
  36. "clock",
  37. "close",
  38. "concat",
  39. "continue",
  40. "dde",
  41. "dict",
  42. "encoding",
  43. "eof",
  44. "error",
  45. "eval",
  46. "exec",
  47. "exit",
  48. "expr",
  49. "fblocked",
  50. "fconfigure",
  51. "fcopy",
  52. "file",
  53. "fileevent",
  54. "filename",
  55. "flush",
  56. "for",
  57. "foreach",
  58. "format",
  59. "gets",
  60. "glob",
  61. "global",
  62. "history",
  63. "http",
  64. "if",
  65. "incr",
  66. "info",
  67. "interp",
  68. "join",
  69. "lappend|10",
  70. "lassign|10",
  71. "lindex|10",
  72. "linsert|10",
  73. "list",
  74. "llength|10",
  75. "load",
  76. "lrange|10",
  77. "lrepeat|10",
  78. "lreplace|10",
  79. "lreverse|10",
  80. "lsearch|10",
  81. "lset|10",
  82. "lsort|10",
  83. "mathfunc",
  84. "mathop",
  85. "memory",
  86. "msgcat",
  87. "namespace",
  88. "open",
  89. "package",
  90. "parray",
  91. "pid",
  92. "pkg::create",
  93. "pkg_mkIndex",
  94. "platform",
  95. "platform::shell",
  96. "proc",
  97. "puts",
  98. "pwd",
  99. "read",
  100. "refchan",
  101. "regexp",
  102. "registry",
  103. "regsub|10",
  104. "rename",
  105. "return",
  106. "safe",
  107. "scan",
  108. "seek",
  109. "set",
  110. "socket",
  111. "source",
  112. "split",
  113. "string",
  114. "subst",
  115. "switch",
  116. "tcl_endOfWord",
  117. "tcl_findLibrary",
  118. "tcl_startOfNextWord",
  119. "tcl_startOfPreviousWord",
  120. "tcl_wordBreakAfter",
  121. "tcl_wordBreakBefore",
  122. "tcltest",
  123. "tclvars",
  124. "tell",
  125. "time",
  126. "tm",
  127. "trace",
  128. "unknown",
  129. "unload",
  130. "unset",
  131. "update",
  132. "uplevel",
  133. "upvar",
  134. "variable",
  135. "vwait",
  136. "while"
  137. ];
  138. return {
  139. name: 'Tcl',
  140. aliases: [ 'tk' ],
  141. keywords: KEYWORDS,
  142. contains: [
  143. hljs.COMMENT(';[ \\t]*#', '$'),
  144. hljs.COMMENT('^[ \\t]*#', '$'),
  145. {
  146. beginKeywords: 'proc',
  147. end: '[\\{]',
  148. excludeEnd: true,
  149. contains: [
  150. {
  151. className: 'title',
  152. begin: '[ \\t\\n\\r]+(::)?[a-zA-Z_]((::)?[a-zA-Z0-9_])*',
  153. end: '[ \\t\\n\\r]',
  154. endsWithParent: true,
  155. excludeEnd: true
  156. }
  157. ]
  158. },
  159. {
  160. className: "variable",
  161. variants: [
  162. { begin: regex.concat(
  163. /\$/,
  164. regex.optional(/::/),
  165. TCL_IDENT,
  166. '(::',
  167. TCL_IDENT,
  168. ')*'
  169. ) },
  170. {
  171. begin: '\\$\\{(::)?[a-zA-Z_]((::)?[a-zA-Z0-9_])*',
  172. end: '\\}',
  173. contains: [ NUMBER ]
  174. }
  175. ]
  176. },
  177. {
  178. className: 'string',
  179. contains: [ hljs.BACKSLASH_ESCAPE ],
  180. variants: [ hljs.inherit(hljs.QUOTE_STRING_MODE, { illegal: null }) ]
  181. },
  182. NUMBER
  183. ]
  184. };
  185. }
  186. export { tcl as default };