vbscript.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. Language: VBScript
  3. Description: VBScript ("Microsoft Visual Basic Scripting Edition") is an Active Scripting language developed by Microsoft that is modeled on Visual Basic.
  4. Author: Nikita Ledyaev <lenikita@yandex.ru>
  5. Contributors: Michal Gabrukiewicz <mgabru@gmail.com>
  6. Website: https://en.wikipedia.org/wiki/VBScript
  7. Category: scripting
  8. */
  9. /** @type LanguageFn */
  10. function vbscript(hljs) {
  11. const regex = hljs.regex;
  12. const BUILT_IN_FUNCTIONS = [
  13. "lcase",
  14. "month",
  15. "vartype",
  16. "instrrev",
  17. "ubound",
  18. "setlocale",
  19. "getobject",
  20. "rgb",
  21. "getref",
  22. "string",
  23. "weekdayname",
  24. "rnd",
  25. "dateadd",
  26. "monthname",
  27. "now",
  28. "day",
  29. "minute",
  30. "isarray",
  31. "cbool",
  32. "round",
  33. "formatcurrency",
  34. "conversions",
  35. "csng",
  36. "timevalue",
  37. "second",
  38. "year",
  39. "space",
  40. "abs",
  41. "clng",
  42. "timeserial",
  43. "fixs",
  44. "len",
  45. "asc",
  46. "isempty",
  47. "maths",
  48. "dateserial",
  49. "atn",
  50. "timer",
  51. "isobject",
  52. "filter",
  53. "weekday",
  54. "datevalue",
  55. "ccur",
  56. "isdate",
  57. "instr",
  58. "datediff",
  59. "formatdatetime",
  60. "replace",
  61. "isnull",
  62. "right",
  63. "sgn",
  64. "array",
  65. "snumeric",
  66. "log",
  67. "cdbl",
  68. "hex",
  69. "chr",
  70. "lbound",
  71. "msgbox",
  72. "ucase",
  73. "getlocale",
  74. "cos",
  75. "cdate",
  76. "cbyte",
  77. "rtrim",
  78. "join",
  79. "hour",
  80. "oct",
  81. "typename",
  82. "trim",
  83. "strcomp",
  84. "int",
  85. "createobject",
  86. "loadpicture",
  87. "tan",
  88. "formatnumber",
  89. "mid",
  90. "split",
  91. "cint",
  92. "sin",
  93. "datepart",
  94. "ltrim",
  95. "sqr",
  96. "time",
  97. "derived",
  98. "eval",
  99. "date",
  100. "formatpercent",
  101. "exp",
  102. "inputbox",
  103. "left",
  104. "ascw",
  105. "chrw",
  106. "regexp",
  107. "cstr",
  108. "err"
  109. ];
  110. const BUILT_IN_OBJECTS = [
  111. "server",
  112. "response",
  113. "request",
  114. // take no arguments so can be called without ()
  115. "scriptengine",
  116. "scriptenginebuildversion",
  117. "scriptengineminorversion",
  118. "scriptenginemajorversion"
  119. ];
  120. const BUILT_IN_CALL = {
  121. begin: regex.concat(regex.either(...BUILT_IN_FUNCTIONS), "\\s*\\("),
  122. // relevance 0 because this is acting as a beginKeywords really
  123. relevance: 0,
  124. keywords: { built_in: BUILT_IN_FUNCTIONS }
  125. };
  126. const LITERALS = [
  127. "true",
  128. "false",
  129. "null",
  130. "nothing",
  131. "empty"
  132. ];
  133. const KEYWORDS = [
  134. "call",
  135. "class",
  136. "const",
  137. "dim",
  138. "do",
  139. "loop",
  140. "erase",
  141. "execute",
  142. "executeglobal",
  143. "exit",
  144. "for",
  145. "each",
  146. "next",
  147. "function",
  148. "if",
  149. "then",
  150. "else",
  151. "on",
  152. "error",
  153. "option",
  154. "explicit",
  155. "new",
  156. "private",
  157. "property",
  158. "let",
  159. "get",
  160. "public",
  161. "randomize",
  162. "redim",
  163. "rem",
  164. "select",
  165. "case",
  166. "set",
  167. "stop",
  168. "sub",
  169. "while",
  170. "wend",
  171. "with",
  172. "end",
  173. "to",
  174. "elseif",
  175. "is",
  176. "or",
  177. "xor",
  178. "and",
  179. "not",
  180. "class_initialize",
  181. "class_terminate",
  182. "default",
  183. "preserve",
  184. "in",
  185. "me",
  186. "byval",
  187. "byref",
  188. "step",
  189. "resume",
  190. "goto"
  191. ];
  192. return {
  193. name: 'VBScript',
  194. aliases: [ 'vbs' ],
  195. case_insensitive: true,
  196. keywords: {
  197. keyword: KEYWORDS,
  198. built_in: BUILT_IN_OBJECTS,
  199. literal: LITERALS
  200. },
  201. illegal: '//',
  202. contains: [
  203. BUILT_IN_CALL,
  204. hljs.inherit(hljs.QUOTE_STRING_MODE, { contains: [ { begin: '""' } ] }),
  205. hljs.COMMENT(
  206. /'/,
  207. /$/,
  208. { relevance: 0 }
  209. ),
  210. hljs.C_NUMBER_MODE
  211. ]
  212. };
  213. }
  214. export { vbscript as default };