tcl.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /**
  2. * @param {string} value
  3. * @returns {RegExp}
  4. * */
  5. /**
  6. * @param {RegExp | string } re
  7. * @returns {string}
  8. */
  9. function source(re) {
  10. if (!re) return null;
  11. if (typeof re === "string") return re;
  12. return re.source;
  13. }
  14. /**
  15. * @param {RegExp | string } re
  16. * @returns {string}
  17. */
  18. function optional(re) {
  19. return concat('(', re, ')?');
  20. }
  21. /**
  22. * @param {...(RegExp | string) } args
  23. * @returns {string}
  24. */
  25. function concat(...args) {
  26. const joined = args.map((x) => source(x)).join("");
  27. return joined;
  28. }
  29. /*
  30. Language: Tcl
  31. Description: Tcl is a very simple programming language.
  32. Author: Radek Liska <radekliska@gmail.com>
  33. Website: https://www.tcl.tk/about/language.html
  34. */
  35. function tcl(hljs) {
  36. const TCL_IDENT = /[a-zA-Z_][a-zA-Z0-9_]*/;
  37. const NUMBER = {
  38. className: 'number',
  39. variants: [hljs.BINARY_NUMBER_MODE, hljs.C_NUMBER_MODE]
  40. };
  41. return {
  42. name: 'Tcl',
  43. aliases: ['tk'],
  44. keywords: 'after append apply array auto_execok auto_import auto_load auto_mkindex ' +
  45. 'auto_mkindex_old auto_qualify auto_reset bgerror binary break catch cd chan clock ' +
  46. 'close concat continue dde dict encoding eof error eval exec exit expr fblocked ' +
  47. 'fconfigure fcopy file fileevent filename flush for foreach format gets glob global ' +
  48. 'history http if incr info interp join lappend|10 lassign|10 lindex|10 linsert|10 list ' +
  49. 'llength|10 load lrange|10 lrepeat|10 lreplace|10 lreverse|10 lsearch|10 lset|10 lsort|10 '+
  50. 'mathfunc mathop memory msgcat namespace open package parray pid pkg::create pkg_mkIndex '+
  51. 'platform platform::shell proc puts pwd read refchan regexp registry regsub|10 rename '+
  52. 'return safe scan seek set socket source split string subst switch tcl_endOfWord '+
  53. 'tcl_findLibrary tcl_startOfNextWord tcl_startOfPreviousWord tcl_wordBreakAfter '+
  54. 'tcl_wordBreakBefore tcltest tclvars tell time tm trace unknown unload unset update '+
  55. 'uplevel upvar variable vwait while',
  56. contains: [
  57. hljs.COMMENT(';[ \\t]*#', '$'),
  58. hljs.COMMENT('^[ \\t]*#', '$'),
  59. {
  60. beginKeywords: 'proc',
  61. end: '[\\{]',
  62. excludeEnd: true,
  63. contains: [
  64. {
  65. className: 'title',
  66. begin: '[ \\t\\n\\r]+(::)?[a-zA-Z_]((::)?[a-zA-Z0-9_])*',
  67. end: '[ \\t\\n\\r]',
  68. endsWithParent: true,
  69. excludeEnd: true
  70. }
  71. ]
  72. },
  73. {
  74. className: "variable",
  75. variants: [
  76. {
  77. begin: concat(
  78. /\$/,
  79. optional(/::/),
  80. TCL_IDENT,
  81. '(::',
  82. TCL_IDENT,
  83. ')*'
  84. )
  85. },
  86. {
  87. begin: '\\$\\{(::)?[a-zA-Z_]((::)?[a-zA-Z0-9_])*',
  88. end: '\\}',
  89. contains: [
  90. NUMBER
  91. ]
  92. }
  93. ]
  94. },
  95. {
  96. className: 'string',
  97. contains: [hljs.BACKSLASH_ESCAPE],
  98. variants: [
  99. hljs.inherit(hljs.QUOTE_STRING_MODE, {illegal: null})
  100. ]
  101. },
  102. NUMBER
  103. ]
  104. }
  105. }
  106. module.exports = tcl;