vbnet.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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: Visual Basic .NET
  35. Description: Visual Basic .NET (VB.NET) is a multi-paradigm, object-oriented programming language, implemented on the .NET Framework.
  36. Authors: Poren Chiang <ren.chiang@gmail.com>, Jan Pilzer
  37. Website: https://docs.microsoft.com/dotnet/visual-basic/getting-started
  38. Category: common
  39. */
  40. /** @type LanguageFn */
  41. function vbnet(hljs) {
  42. /**
  43. * Character Literal
  44. * Either a single character ("a"C) or an escaped double quote (""""C).
  45. */
  46. const CHARACTER = {
  47. className: 'string',
  48. begin: /"(""|[^/n])"C\b/
  49. };
  50. const STRING = {
  51. className: 'string',
  52. begin: /"/,
  53. end: /"/,
  54. illegal: /\n/,
  55. contains: [
  56. {
  57. // double quote escape
  58. begin: /""/
  59. }
  60. ]
  61. };
  62. /** Date Literals consist of a date, a time, or both separated by whitespace, surrounded by # */
  63. const MM_DD_YYYY = /\d{1,2}\/\d{1,2}\/\d{4}/;
  64. const YYYY_MM_DD = /\d{4}-\d{1,2}-\d{1,2}/;
  65. const TIME_12H = /(\d|1[012])(:\d+){0,2} *(AM|PM)/;
  66. const TIME_24H = /\d{1,2}(:\d{1,2}){1,2}/;
  67. const DATE = {
  68. className: 'literal',
  69. variants: [
  70. {
  71. // #YYYY-MM-DD# (ISO-Date) or #M/D/YYYY# (US-Date)
  72. begin: concat(/# */, either(YYYY_MM_DD, MM_DD_YYYY), / *#/)
  73. },
  74. {
  75. // #H:mm[:ss]# (24h Time)
  76. begin: concat(/# */, TIME_24H, / *#/)
  77. },
  78. {
  79. // #h[:mm[:ss]] A# (12h Time)
  80. begin: concat(/# */, TIME_12H, / *#/)
  81. },
  82. {
  83. // date plus time
  84. begin: concat(
  85. /# */,
  86. either(YYYY_MM_DD, MM_DD_YYYY),
  87. / +/,
  88. either(TIME_12H, TIME_24H),
  89. / *#/
  90. )
  91. }
  92. ]
  93. };
  94. const NUMBER = {
  95. className: 'number',
  96. relevance: 0,
  97. variants: [
  98. {
  99. // Float
  100. begin: /\b\d[\d_]*((\.[\d_]+(E[+-]?[\d_]+)?)|(E[+-]?[\d_]+))[RFD@!#]?/
  101. },
  102. {
  103. // Integer (base 10)
  104. begin: /\b\d[\d_]*((U?[SIL])|[%&])?/
  105. },
  106. {
  107. // Integer (base 16)
  108. begin: /&H[\dA-F_]+((U?[SIL])|[%&])?/
  109. },
  110. {
  111. // Integer (base 8)
  112. begin: /&O[0-7_]+((U?[SIL])|[%&])?/
  113. },
  114. {
  115. // Integer (base 2)
  116. begin: /&B[01_]+((U?[SIL])|[%&])?/
  117. }
  118. ]
  119. };
  120. const LABEL = {
  121. className: 'label',
  122. begin: /^\w+:/
  123. };
  124. const DOC_COMMENT = hljs.COMMENT(/'''/, /$/, {
  125. contains: [
  126. {
  127. className: 'doctag',
  128. begin: /<\/?/,
  129. end: />/
  130. }
  131. ]
  132. });
  133. const COMMENT = hljs.COMMENT(null, /$/, {
  134. variants: [
  135. {
  136. begin: /'/
  137. },
  138. {
  139. // TODO: Use `beforeMatch:` for leading spaces
  140. begin: /([\t ]|^)REM(?=\s)/
  141. }
  142. ]
  143. });
  144. const DIRECTIVES = {
  145. className: 'meta',
  146. // TODO: Use `beforeMatch:` for indentation once available
  147. begin: /[\t ]*#(const|disable|else|elseif|enable|end|externalsource|if|region)\b/,
  148. end: /$/,
  149. keywords: {
  150. 'meta-keyword':
  151. 'const disable else elseif enable end externalsource if region then'
  152. },
  153. contains: [ COMMENT ]
  154. };
  155. return {
  156. name: 'Visual Basic .NET',
  157. aliases: [ 'vb' ],
  158. case_insensitive: true,
  159. classNameAliases: {
  160. label: 'symbol'
  161. },
  162. keywords: {
  163. keyword:
  164. 'addhandler alias aggregate ansi as async assembly auto binary by byref byval ' + /* a-b */
  165. 'call case catch class compare const continue custom declare default delegate dim distinct do ' + /* c-d */
  166. 'each equals else elseif end enum erase error event exit explicit finally for friend from function ' + /* e-f */
  167. 'get global goto group handles if implements imports in inherits interface into iterator ' + /* g-i */
  168. 'join key let lib loop me mid module mustinherit mustoverride mybase myclass ' + /* j-m */
  169. 'namespace narrowing new next notinheritable notoverridable ' + /* n */
  170. 'of off on operator option optional order overloads overridable overrides ' + /* o */
  171. 'paramarray partial preserve private property protected public ' + /* p */
  172. 'raiseevent readonly redim removehandler resume return ' + /* r */
  173. 'select set shadows shared skip static step stop structure strict sub synclock ' + /* s */
  174. 'take text then throw to try unicode until using when where while widening with withevents writeonly yield' /* t-y */,
  175. built_in:
  176. // Operators https://docs.microsoft.com/dotnet/visual-basic/language-reference/operators
  177. 'addressof and andalso await directcast gettype getxmlnamespace is isfalse isnot istrue like mod nameof new not or orelse trycast typeof xor ' +
  178. // Type Conversion Functions https://docs.microsoft.com/dotnet/visual-basic/language-reference/functions/type-conversion-functions
  179. 'cbool cbyte cchar cdate cdbl cdec cint clng cobj csbyte cshort csng cstr cuint culng cushort',
  180. type:
  181. // Data types https://docs.microsoft.com/dotnet/visual-basic/language-reference/data-types
  182. 'boolean byte char date decimal double integer long object sbyte short single string uinteger ulong ushort',
  183. literal: 'true false nothing'
  184. },
  185. illegal:
  186. '//|\\{|\\}|endif|gosub|variant|wend|^\\$ ' /* reserved deprecated keywords */,
  187. contains: [
  188. CHARACTER,
  189. STRING,
  190. DATE,
  191. NUMBER,
  192. LABEL,
  193. DOC_COMMENT,
  194. COMMENT,
  195. DIRECTIVES
  196. ]
  197. };
  198. }
  199. module.exports = vbnet;