vbscript.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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) } args
  16. * @returns {string}
  17. */
  18. function concat(...args) {
  19. const joined = args.map((x) => source(x)).join("");
  20. return joined;
  21. }
  22. /**
  23. * Any of the passed expresssions may match
  24. *
  25. * Creates a huge this | this | that | that match
  26. * @param {(RegExp | string)[] } args
  27. * @returns {string}
  28. */
  29. function either(...args) {
  30. const joined = '(' + args.map((x) => source(x)).join("|") + ")";
  31. return joined;
  32. }
  33. /*
  34. Language: VBScript
  35. Description: VBScript ("Microsoft Visual Basic Scripting Edition") is an Active Scripting language developed by Microsoft that is modeled on Visual Basic.
  36. Author: Nikita Ledyaev <lenikita@yandex.ru>
  37. Contributors: Michal Gabrukiewicz <mgabru@gmail.com>
  38. Website: https://en.wikipedia.org/wiki/VBScript
  39. Category: scripting
  40. */
  41. /** @type LanguageFn */
  42. function vbscript(hljs) {
  43. const BUILT_IN_FUNCTIONS = ('lcase month vartype instrrev ubound setlocale getobject rgb getref string ' +
  44. 'weekdayname rnd dateadd monthname now day minute isarray cbool round formatcurrency ' +
  45. 'conversions csng timevalue second year space abs clng timeserial fixs len asc ' +
  46. 'isempty maths dateserial atn timer isobject filter weekday datevalue ccur isdate ' +
  47. 'instr datediff formatdatetime replace isnull right sgn array snumeric log cdbl hex ' +
  48. 'chr lbound msgbox ucase getlocale cos cdate cbyte rtrim join hour oct typename trim ' +
  49. 'strcomp int createobject loadpicture tan formatnumber mid ' +
  50. 'split cint sin datepart ltrim sqr ' +
  51. 'time derived eval date formatpercent exp inputbox left ascw ' +
  52. 'chrw regexp cstr err').split(" ");
  53. const BUILT_IN_OBJECTS = [
  54. "server",
  55. "response",
  56. "request",
  57. // take no arguments so can be called without ()
  58. "scriptengine",
  59. "scriptenginebuildversion",
  60. "scriptengineminorversion",
  61. "scriptenginemajorversion"
  62. ];
  63. const BUILT_IN_CALL = {
  64. begin: concat(either(...BUILT_IN_FUNCTIONS), "\\s*\\("),
  65. // relevance 0 because this is acting as a beginKeywords really
  66. relevance:0,
  67. keywords: {
  68. built_in: BUILT_IN_FUNCTIONS
  69. }
  70. };
  71. return {
  72. name: 'VBScript',
  73. aliases: ['vbs'],
  74. case_insensitive: true,
  75. keywords: {
  76. keyword:
  77. 'call class const dim do loop erase execute executeglobal exit for each next function ' +
  78. 'if then else on error option explicit new private property let get public randomize ' +
  79. 'redim rem select case set stop sub while wend with end to elseif is or xor and not ' +
  80. 'class_initialize class_terminate default preserve in me byval byref step resume goto',
  81. built_in: BUILT_IN_OBJECTS,
  82. literal:
  83. 'true false null nothing empty'
  84. },
  85. illegal: '//',
  86. contains: [
  87. BUILT_IN_CALL,
  88. hljs.inherit(hljs.QUOTE_STRING_MODE, {contains: [{begin: '""'}]}),
  89. hljs.COMMENT(
  90. /'/,
  91. /$/,
  92. {
  93. relevance: 0
  94. }
  95. ),
  96. hljs.C_NUMBER_MODE
  97. ]
  98. };
  99. }
  100. module.exports = vbscript;