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