vbnet.js 5.2 KB

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