Skip to content
This repository was archived by the owner on Apr 22, 2020. It is now read-only.

Commit 142f35a

Browse files
author
mikesamuel
committed
language handler for VB
1 parent 7e138d6 commit 142f35a

File tree

4 files changed

+161
-1
lines changed

4 files changed

+161
-1
lines changed

CHANGES.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,9 @@ <h2>14 Jul 2008</h2>
5757
affect the tokenization of prettified code.
5858
See the issue 22 <a href="tests/prettify_test.html#issue22">testcase</a>.</code>
5959
</ul>
60+
<h2>6 Jan 2009</h2>
61+
<ul>
62+
<li>Language handler for Visual Baseic</li>
63+
</ul>
6064
</body>
6165
</html>

README.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ <h2>FAQ</h2>
6565
<h3>Which languages does it work for?</h3>
6666
<p>The comments in <tt>prettify.js</tt> are authoritative but the lexer
6767
should work on a number of languages including C and friends,
68-
Java, Python, Bash, SQL, HTML, XML, CSS, Javascript, and Makefiles.
68+
Java, Python, Bash, VB, SQL, HTML, XML, CSS, Javascript, and Makefiles.
6969
It works passably on Ruby, PHP and Awk and a decent subset of Perl, but,
7070
because of commenting conventions, doesn't work on Smalltalk, or
7171
CAML-like languages.</p>
@@ -76,6 +76,8 @@ <h3>Which languages does it work for?</h3>
7676
<p>And similarly for <a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-lua.js"
7777
><code>LUA</code></a>, <a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-ml.js"
7878
><code>OCAML, SML, F#</code></a>,
79+
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-vb.js"
80+
><code>Visual Basic</code></a>,
7981
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-sql.js"
8082
><code>SQL</code></a>, and
8183
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-proto.js"

src/lang-vb.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright (C) 2009 Google Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
16+
17+
/**
18+
* @fileoverview
19+
* Registers a language handler for various flavors of basic.
20+
*
21+
*
22+
* To use, include prettify.js and this file in your HTML page.
23+
* Then put your code in an HTML tag like
24+
* <pre class="prettyprint lang-vb"></pre>
25+
*
26+
*
27+
* http://msdn.microsoft.com/en-us/library/aa711638(VS.71).aspx defines the
28+
* visual basic grammar lexical grammar.
29+
*
30+
31+
*/
32+
33+
PR.registerLangHandler(
34+
PR.createSimpleLexer(
35+
[
36+
// Whitespace
37+
[PR.PR_PLAIN, /^[\t\n\r \xA0\u2028\u2029]+/, null, '\t\n\r \xA0\u2028\u2029'],
38+
// A double quoted string with quotes escaped by doubling them.
39+
// A single character can be suffixed with C.
40+
[PR.PR_STRING, /^(?:[\"\u201C\u201D](?:[^\"\u201C\u201D]|[\"\u201C\u201D]{2})[\"\u201C\u201D][cC]|[\"\u201C\u201D](?:[^\"\u201C\u201D]|[\"\u201C\u201D]{2})*[\"\u201C\u201D])/, null,
41+
'"\u201C\u201D'],
42+
// A comment starts with a single quote and runs until the end of the
43+
// line.
44+
[PR.PR_COMMENT, /^[\'\u2018\u2019][^\r\n\u2028\u2029]*/, null, '\'\u2018\u2019']
45+
],
46+
[
47+
[PR.PR_KEYWORD, /^(?:AddHandler|AddressOf|Alias|And|AndAlso|Ansi|As|Assembly|Auto|Boolean|ByRef|Byte|ByVal|Call|Case|Catch|CBool|CByte|CChar|CDate|CDbl|CDec|Char|CInt|Class|CLng|CObj|Const|CShort|CSng|CStr|CType|Date|Decimal|Declare|Default|Delegate|Dim|DirectCast|Do|Double|Each|Else|ElseIf|End|EndIf|Enum|Erase|Error|Event|Exit|Finally|For|Friend|Function|Get|GetType|GoSub|GoTo|Handles|If|Implements|Imports|In|Inherits|Integer|Interface|Is|Let|Lib|Like|Long|Loop|Me|Mod|Module|MustInherit|MustOverride|MyBase|MyClass|Namespace|New|Next|Not|NotInheritable|NotOverridable|Object|On|Option|Optional|Or|OrElse|Overloads|Overridable|Overrides|ParamArray|Preserve|Private|Property|Protected|Public|RaiseEvent|ReadOnly|ReDim|RemoveHandler|Resume|Return|Select|Set|Shadows|Shared|Short|Single|Static|Step|Stop|String|Structure|Sub|SyncLock|Then|Throw|To|Try|TypeOf|Unicode|Until|Variant|Wend|When|While|With|WithEvents|WriteOnly|Xor|EndIf|GoSub|Let|Variant|Wend)\b/i, null],
48+
// A second comment form
49+
[PR.PR_COMMENT, /^REM[^\r\n\u2028\u2029]*/i],
50+
// A boolean, numeric, or date literal.
51+
[PR.PR_LITERAL,
52+
/^(?:True\b|False\b|Nothing\b|\d+(?:E[+\-]?\d+[FRD]?|[FRDSIL])?|(?:&H[0-9A-F]+|&O[0-7]+)[SIL]?|\d*\.\d+(?:E[+\-]?\d+)?[FRD]?|#\s+(?:\d+[\-\/]\d+[\-\/]\d+(?:\s+\d+:\d+(?::\d+)?(\s*(?:AM|PM))?)?|\d+:\d+(?::\d+)?(\s*(?:AM|PM))?)\s+#)/i],
53+
// An identifier?
54+
[PR.PR_PLAIN, /^(?:(?:[a-z]|_\w)\w*|\[(?:[a-z]|_\w)\w*\])/i],
55+
// A run of punctuation
56+
[PR.PR_PUNCTUATION,
57+
/^[^\w\t\n\r \"\'\[\]\xA0\u2018\u2019\u201C\u201D\u2028\u2029]+/],
58+
// A run of punctuation
59+
[PR.PR_PUNCTUATION, /^(?:\[|\])/]
60+
]),
61+
['vb', 'vbs']);

tests/prettify_test.html

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
onerror="alert('Error: failed to load ' + this.src)"></script>
1515
<script src="../src/lang-sql.js" type="text/javascript"
1616
onerror="alert('Error: failed to load ' + this.src)"></script>
17+
<script src="../src/lang-vb.js" type="text/javascript"
18+
onerror="alert('Error: failed to load ' + this.src)"></script>
1719
<script type="text/javascript">
1820
// get accurate timing
1921
PR_SHOULD_USE_CONTINUATION = false;
@@ -839,6 +841,53 @@ <h1>Bug 42 - Lisp Syntax Highlighting</h1>
839841
)
840842
</pre>
841843

844+
<h1>Bug 27 - VBScript w/ language specified</h1>
845+
<pre class="prettyprint lang-vb" id="issue27">
846+
Imports System
847+
848+
Class [class]
849+
Shared Sub [shared](ByVal [boolean] As Boolean)
850+
If [boolean] Then
851+
Console.WriteLine("true")
852+
Else
853+
Console.WriteLine("false")
854+
End If
855+
End Sub
856+
End Class
857+
858+
Module [module]
859+
Sub Main()
860+
[class].[shared](True)
861+
862+
' This prints out: &quot;.
863+
Console.WriteLine("""")
864+
865+
' This prints out: a&quot;b.
866+
Console.WriteLine("a""b")
867+
868+
' This prints out: a.
869+
Console.WriteLine("a"c)
870+
871+
' This prints out: &quot;.
872+
Console.WriteLine(""""c)
873+
End Sub
874+
End Module
875+
876+
Dim d As Date
877+
d = # 8/23/1970 3:45:39AM #
878+
d = # 8/23/1970 #
879+
d = # 3:45:39AM #
880+
d = # 3:45:39 #
881+
d = # 13:45:39 #
882+
d = # 13:45:39PM #
883+
884+
Dim n As Float
885+
n = (0.0, .99F, 1.0E-2D, 1.0E+3D, .5E4, 1E3R, 4D)
886+
887+
Dim i As Integer
888+
i = (0, 123, 45L, &amp;HA0I, &amp;O177S)
889+
</pre>
890+
842891
<h1>Bug 33 - OCaml and F#</h1>
843892
<pre class="prettyprint lang-ml" id="issue33">
844893
(*
@@ -1929,6 +1978,50 @@ <h1>Protocol Buffers</h1>
19291978
'&nbsp; `END`KWDend`END`PLN<br>' +
19301979
'&nbsp; `END`KWDreturn`END`PLN shellsort<br>' +
19311980
'`END`KWDend`END'),
1981+
issue27: (
1982+
'`KWDImports`END`PLN System<br>' +
1983+
'<br>' +
1984+
'`END`KWDClass`END`PLN [class]<br>' +
1985+
'&nbsp; &nbsp; `END`KWDShared`END`PLN `END`KWDSub`END`PLN [shared]`END`PUN(`END`KWDByVal`END`PLN [boolean] `END`KWDAs`END`PLN `END`KWDBoolean`END`PUN)`END`PLN<br>' +
1986+
'&nbsp; &nbsp; &nbsp; &nbsp; `END`KWDIf`END`PLN [boolean] `END`KWDThen`END`PLN<br>' +
1987+
'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console`END`PUN.`END`PLNWriteLine`END`PUN(`END`STR"true"`END`PUN)`END`PLN<br>' +
1988+
'&nbsp; &nbsp; &nbsp; &nbsp; `END`KWDElse`END`PLN<br>' +
1989+
'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console`END`PUN.`END`PLNWriteLine`END`PUN(`END`STR"false"`END`PUN)`END`PLN<br>' +
1990+
'&nbsp; &nbsp; &nbsp; &nbsp; `END`KWDEnd`END`PLN `END`KWDIf`END`PLN<br>' +
1991+
'&nbsp; &nbsp; `END`KWDEnd`END`PLN `END`KWDSub`END`PLN<br>' +
1992+
'`END`KWDEnd`END`PLN `END`KWDClass`END`PLN<br>' +
1993+
'<br>' +
1994+
'`END`KWDModule`END`PLN [module]<br>' +
1995+
'&nbsp; &nbsp; `END`KWDSub`END`PLN Main`END`PUN()`END`PLN<br>' +
1996+
'&nbsp; &nbsp; &nbsp; &nbsp; [class]`END`PUN.`END`PLN[shared]`END`PUN(`END`LITTrue`END`PUN)`END`PLN<br>' +
1997+
'<br>' +
1998+
'&nbsp; &nbsp; &nbsp; &nbsp; `END`COM\' This prints out: \".`END`PLN<br>' +
1999+
'&nbsp; &nbsp; &nbsp; &nbsp; Console`END`PUN.`END`PLNWriteLine`END`PUN(`END`STR""""`END`PUN)`END`PLN<br>' +
2000+
'<br>' +
2001+
'&nbsp; &nbsp; &nbsp; &nbsp; `END`COM\' This prints out: a"b.`END`PLN<br>' +
2002+
'&nbsp; &nbsp; &nbsp; &nbsp; Console`END`PUN.`END`PLNWriteLine`END`PUN(`END`STR"a""b"`END`PUN)`END`PLN<br>' +
2003+
'<br>' +
2004+
'&nbsp; &nbsp; &nbsp; &nbsp; `END`COM\' This prints out: a.`END`PLN<br>' +
2005+
'&nbsp; &nbsp; &nbsp; &nbsp; Console`END`PUN.`END`PLNWriteLine`END`PUN(`END`STR"a"c`END`PUN)`END`PLN<br>' +
2006+
'<br>' +
2007+
'&nbsp; &nbsp; &nbsp; &nbsp; `END`COM\' This prints out: ".`END`PLN<br>' +
2008+
'&nbsp; &nbsp; &nbsp; &nbsp; Console`END`PUN.`END`PLNWriteLine`END`PUN(`END`STR""""c`END`PUN)`END`PLN<br>' +
2009+
'&nbsp; &nbsp; `END`KWDEnd`END`PLN `END`KWDSub`END`PLN<br>' +
2010+
'`END`KWDEnd`END`PLN `END`KWDModule`END`PLN<br>' +
2011+
'<br>' +
2012+
'`END`KWDDim`END`PLN d `END`KWDAs`END`PLN `END`KWDDate`END`PLN<br>' +
2013+
'd `END`PUN=`END`PLN `END`LIT# 8/23/1970 3:45:39AM #`END`PLN<br>' +
2014+
'd `END`PUN=`END`PLN `END`LIT# 8/23/1970 #`END`PLN<br>' +
2015+
'd `END`PUN=`END`PLN `END`LIT# 3:45:39AM #`END`PLN<br>' +
2016+
'd `END`PUN=`END`PLN `END`LIT# 3:45:39 #`END`PLN<br>' +
2017+
'd `END`PUN=`END`PLN `END`LIT# 13:45:39 #`END`PLN<br>' +
2018+
'd `END`PUN=`END`PLN `END`LIT# 13:45:39PM #`END`PLN<br>' +
2019+
'<br>' +
2020+
'`END`KWDDim`END`PLN n `END`KWDAs`END`PLN Float<br>' +
2021+
'n `END`PUN=`END`PLN `END`PUN(`END`LIT0.0`END`PUN,`END`PLN `END`LIT.99F`END`PUN,`END`PLN `END`LIT1.0E-2D`END`PUN,`END`PLN `END`LIT1.0E+3D`END`PUN,`END`PLN `END`LIT.5E4`END`PUN,`END`PLN `END`LIT1E3R`END`PUN,`END`PLN `END`LIT4D`END`PUN)`END`PLN<br>' +
2022+
'<br>' +
2023+
'`END`KWDDim`END`PLN i `END`KWDAs`END`PLN `END`KWDInteger`END`PLN<br>' +
2024+
'i `END`PUN=`END`PLN `END`PUN(`END`LIT0`END`PUN,`END`PLN `END`LIT123`END`PUN,`END`PLN `END`LIT45L`END`PUN,`END`PLN `END`LIT&amp;HA0I`END`PUN,`END`PLN `END`LIT&amp;O177S`END`PUN)`END'),
19322025
issue33: (
19332026
'`COM(*<br>' +
19342027
'&nbsp;* Print the 10th fibonacci number<br>' +

0 commit comments

Comments
 (0)