UNPKG

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