Skip to content

Commit

Permalink
Add support for Visual Basic. Fix #985 (#1382)
Browse files Browse the repository at this point in the history
  • Loading branch information
Golmote authored Apr 11, 2018
1 parent 5a524f7 commit c673ec2
Show file tree
Hide file tree
Showing 15 changed files with 581 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,11 @@
"title": "vim",
"owner": "westonganger"
},
"visual-basic": {
"title": "Visual Basic",
"owner": "Golmote",
"alias": "vb"
},
"wiki": {
"title": "Wiki markup",
"require": "markup",
Expand Down
34 changes: 34 additions & 0 deletions components/prism-visual-basic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Prism.languages['visual-basic'] = {
'comment': {
pattern: /(?:['‘’]|REM\b).*/i,
inside: {
'keyword': /^REM/i
}
},
'directive': {
pattern: /#(?:Const|Else|ElseIf|End|ExternalChecksum|ExternalSource|If|Region)(?:[^\S\r\n]_[^\S\r\n]*(?:\r\n?|\n)|.)+/i,
alias: 'comment',
greedy: true
},
'string': {
pattern: /["“”](?:["“”]{2}|[^"“”])*["“”]C?/i,
greedy: true
},
'date': {
pattern: /#[^\S\r\n]*(?:\d+([/-])\d+\1\d+(?:[^\S\r\n]+(?:\d+[^\S\r\n]*(?:AM|PM)|\d+:\d+(?::\d+)?(?:[^\S\r\n]*(?:AM|PM))?))?|(?:\d+[^\S\r\n]*(?:AM|PM)|\d+:\d+(?::\d+)?(?:[^\S\r\n]*(?:AM|PM))?))[^\S\r\n]*#/i,
alias: 'builtin'
},
'number': /(?:(?:\b\d+(?:\.\d+)?|\.\d+)(?:E[+-]?\d+)?|&[HO][\dA-F]+)(?:U?[ILS]|[FRD])?/i,
'boolean': /\b(?:True|False|Nothing)\b/i,
'keyword': /\b(?:AddHandler|AddressOf|Alias|And(?:Also)?|As|Boolean|ByRef|Byte|ByVal|Call|Case|Catch|C(?:Bool|Byte|Char|Date|Dbl|Dec|Int|Lng|Obj|SByte|Short|Sng|Str|Type|UInt|ULng|UShort)|Char|Class|Const|Continue|Date|Decimal|Declare|Default|Delegate|Dim|DirectCast|Do|Double|Each|Else(?:If)?|End(?:If)?|Enum|Erase|Error|Event|Exit|Finally|For|Friend|Function|Get(?:Type|XMLNamespace)?|Global|GoSub|GoTo|Handles|If|Implements|Imports|In|Inherits|Integer|Interface|Is|IsNot|Let|Lib|Like|Long|Loop|Me|Mod|Module|Must(?:Inherit|Override)|My(?:Base|Class)|Namespace|Narrowing|New|Next|Not(?:Inheritable|Overridable)?|Object|Of|On|Operator|Option(?:al)?|Or(?:Else)?|Out|Overloads|Overridable|Overrides|ParamArray|Partial|Private|Property|Protected|Public|RaiseEvent|ReadOnly|ReDim|RemoveHandler|Resume|Return|SByte|Select|Set|Shadows|Shared|short|Single|Static|Step|Stop|String|Structure|Sub|SyncLock|Then|Throw|To|Try|TryCast|TypeOf|U(?:Integer|Long|Short)|Using|Variant|Wend|When|While|Widening|With(?:Events)?|WriteOnly|Xor)\b/i,
'operator': [
/[+\-*/\\^<=>&#@$%!]/,
{
pattern: /([^\S\r\n])_(?=[^\S\r\n]*[\r\n])/,
lookbehind: true
}
],
'punctuation': /[{}().,:?]/
};

Prism.languages.vb = Prism.languages['visual-basic'];
1 change: 1 addition & 0 deletions components/prism-visual-basic.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions examples/prism-visual-basic.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<h2>Comments</h2>
<pre><code>' Comment
REM This is a comment too</code></pre>

<h2>Strings and characters</h2>
<pre><code>"Foo""bar"
“”
"a"c</code></pre>

<h2>Dates and times</h2>
<pre><code># 8/23/1970 3:45:39AM #
#8/23/1970 #
# 3:45:39AM #
# 3:45:39#
# 13:45:39 #
# 1AM #
# 13:45:39PM #</code></pre>

<h2>Numbers</h2>
<pre><code>42S
.369E+14
3.1415R</code></pre>

<h2>Preprocessing directives</h2>
<pre><code>#ExternalChecksum("c:\wwwroot\inetpub\test.aspx", _
"{12345678-1234-1234-1234-123456789abc}", _
"1a2b3c4e5f617239a49b9a9c0391849d34950f923fab9484")</code></pre>

<h2>Keywords</h2>
<pre><code>Function AddNumbers(ByVal X As Integer, ByVal Y As Integer)
AddNumbers = X + Y
End Function
Module Test
Sub Main()
End Sub
End Module</code></pre>
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if (!Prism.plugins.toolbar) {
}

// The languages map is built automatically with gulp
var Languages = /*languages_placeholder[*/{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML","css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","arff":"ARFF","asciidoc":"AsciiDoc","asm6502":"6502 Assembly","aspnet":"ASP.NET (C#)","autohotkey":"AutoHotkey","autoit":"AutoIt","basic":"BASIC","csharp":"C#","cpp":"C++","coffeescript":"CoffeeScript","csp":"Content-Security-Policy","css-extras":"CSS Extras","django":"Django/Jinja2","erb":"ERB","fsharp":"F#","glsl":"GLSL","graphql":"GraphQL","http":"HTTP","hpkp":"HTTP Public-Key-Pins","hsts":"HTTP Strict-Transport-Security","ichigojam":"IchigoJam","inform7":"Inform 7","json":"JSON","latex":"LaTeX","livescript":"LiveScript","lolcode":"LOLCODE","markup-templating":"Markup templating","matlab":"MATLAB","mel":"MEL","n4js":"N4JS","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","opencl":"OpenCL","parigp":"PARI/GP","php":"PHP","php-extras":"PHP Extras","plsql":"PL/SQL","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","q":"Q (kdb+ database)","jsx":"React JSX","tsx":"React TSX","renpy":"Ren'py","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","typescript":"TypeScript","vbnet":"VB.Net","vhdl":"VHDL","vim":"vim","wiki":"Wiki markup","xojo":"Xojo (REALbasic)","yaml":"YAML"}/*]*/;
var Languages = /*languages_placeholder[*/{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML","css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","arff":"ARFF","asciidoc":"AsciiDoc","asm6502":"6502 Assembly","aspnet":"ASP.NET (C#)","autohotkey":"AutoHotkey","autoit":"AutoIt","basic":"BASIC","csharp":"C#","cpp":"C++","coffeescript":"CoffeeScript","csp":"Content-Security-Policy","css-extras":"CSS Extras","django":"Django/Jinja2","erb":"ERB","fsharp":"F#","glsl":"GLSL","graphql":"GraphQL","http":"HTTP","hpkp":"HTTP Public-Key-Pins","hsts":"HTTP Strict-Transport-Security","ichigojam":"IchigoJam","inform7":"Inform 7","json":"JSON","latex":"LaTeX","livescript":"LiveScript","lolcode":"LOLCODE","markup-templating":"Markup templating","matlab":"MATLAB","mel":"MEL","n4js":"N4JS","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","opencl":"OpenCL","parigp":"PARI/GP","php":"PHP","php-extras":"PHP Extras","plsql":"PL/SQL","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","q":"Q (kdb+ database)","jsx":"React JSX","tsx":"React TSX","renpy":"Ren'py","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","typescript":"TypeScript","vbnet":"VB.Net","vhdl":"VHDL","vim":"vim","visual-basic":"Visual Basic","wiki":"Wiki markup","xojo":"Xojo (REALbasic)","yaml":"YAML"}/*]*/;
Prism.plugins.toolbar.registerButton('show-language', function(env) {
var pre = env.element.parentNode;
if (!pre || !/pre/i.test(pre.nodeName)) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions tests/languages/visual-basic/boolean_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
True
False
Nothing

----------------------------------------------------

[
["boolean", "True"],
["boolean", "False"],
["boolean", "Nothing"]
]

----------------------------------------------------

Checks for booleans.
25 changes: 25 additions & 0 deletions tests/languages/visual-basic/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'
' Foo "bar"
‘ Foobar
’ Foobar
REM
REM Foobar

----------------------------------------------------

[
["comment", ["'"]],
["comment", ["' Foo \"bar\""]],
["comment", ["‘"]],
["comment", ["‘ Foobar"]],
["comment", ["’"]],
["comment", ["’ Foobar"]],
["comment", [["keyword", "REM"]]],
["comment", [["keyword", "REM"], " Foobar"]]
]

----------------------------------------------------

Checks for comments.
23 changes: 23 additions & 0 deletions tests/languages/visual-basic/date_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 8/23/1970 3:45:39AM #
#8/23/1970 #
# 3:45:39AM #
# 3:45:39#
# 13:45:39 #
# 1AM #
# 13:45:39PM #

----------------------------------------------------

[
["date", "# 8/23/1970 3:45:39AM #"],
["date", "#8/23/1970 #"],
["date", "# 3:45:39AM #"],
["date", "# 3:45:39#"],
["date", "# 13:45:39 #"],
["date", "# 1AM #"],
["date", "# 13:45:39PM #"]
]

----------------------------------------------------

Checks for dates and times.
23 changes: 23 additions & 0 deletions tests/languages/visual-basic/directive_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#Const DebugCode = True
#If DebugCode Then
#End If
#ExternalSource("c:\wwwroot\inetpub\test.aspx", 30)
#End ExternalSource
#ExternalChecksum("c:\wwwroot\inetpub\test.aspx", _
"{12345678-1234-1234-1234-123456789abc}", _
"1a2b3c4e5f617239a49b9a9c0391849d34950f923fab9484")

----------------------------------------------------

[
["directive", "#Const DebugCode = True"],
["directive", "#If DebugCode Then"],
["directive", "#End If"],
["directive", "#ExternalSource(\"c:\\wwwroot\\inetpub\\test.aspx\", 30)"],
["directive", "#End ExternalSource"],
["directive", "#ExternalChecksum(\"c:\\wwwroot\\inetpub\\test.aspx\", _\r\n \"{12345678-1234-1234-1234-123456789abc}\", _\r\n \"1a2b3c4e5f617239a49b9a9c0391849d34950f923fab9484\")"]
]

----------------------------------------------------

Checks for preprocessing directives.
Loading

0 comments on commit c673ec2

Please sign in to comment.