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

Commit 149df22

Browse files
author
mikesamuel
committed
language handler for protocol buffers
1 parent 60cf2e0 commit 149df22

File tree

4 files changed

+96
-5
lines changed

4 files changed

+96
-5
lines changed

README.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,11 @@ <h3>Which languages does it work for?</h3>
7575
><code>lang-lisp.js</code></a>.</p>
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"
78-
><code>OCAML, SML, F#</code></a>, and
78+
><code>OCAML, SML, F#</code></a>,
7979
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-sql.js"
80-
><code>SQL</code></a>.
80+
><code>SQL</code></a>, and
81+
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-proto.js"
82+
><code>Protocol Buffers</code></a>.
8183

8284
<p>If you'd like to add an extension for your favorite language, please
8385
look at lang-lisp.js and file an

src/lang-proto.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (C) 2006 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+
* @fileoverview
18+
* Registers a language handler for Protocol Buffers as described at
19+
* http://code.google.com/p/protobuf/.
20+
*
21+
* Based on the lexical grammar at
22+
* http://research.microsoft.com/fsharp/manual/spec2.aspx#_Toc202383715
23+
*
24+
25+
*/
26+
27+
PR.registerLangHandler(PR.sourceDecorator({
28+
keywords: (
29+
'bool bytes default double enum extend extensions false fixed32 '
30+
+ 'fixed64 float group import int32 int64 max message option '
31+
+ 'optional package repeated required returns rpc service '
32+
+ 'sfixed32 sfixed64 sint32 sint64 string syntax to true uint32 '
33+
+ 'uint64'),
34+
cStyleComments: true
35+
}), ['proto']);

src/prettify.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,12 @@ function _pr_isIE6() {
10691069
keywords: CPP_KEYWORDS,
10701070
hashComments: true,
10711071
cStyleComments: true
1072-
}), ['c', 'cc', 'cpp', 'cs', 'cxx', 'cyc']);
1072+
}), ['c', 'cc', 'cpp', 'cxx', 'cyc']);
1073+
registerLangHandler(sourceDecorator({
1074+
keywords: CSHARP_KEYWORDS,
1075+
hashComments: true,
1076+
cStyleComments: true
1077+
}), ['cs']);
10731078
registerLangHandler(sourceDecorator({
10741079
keywords: JAVA_KEYWORDS,
10751080
cStyleComments: true

tests/prettify_test.html

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
onerror="alert('Error: failed to load ' + this.src)"></script>
1111
<script src="../src/lang-ml.js" type="text/javascript"
1212
onerror="alert('Error: failed to load ' + this.src)"></script>
13+
<script src="../src/lang-proto.js" type="text/javascript"
14+
onerror="alert('Error: failed to load ' + this.src)"></script>
1315
<script src="../src/lang-sql.js" type="text/javascript"
1416
onerror="alert('Error: failed to load ' + this.src)"></script>
1517
<script type="text/javascript">
@@ -864,6 +866,24 @@ <h1>Bug 45 - Square brackets in strings</h1>
864866
variable++;
865867
</pre>
866868

869+
<h1>Protocol Buffers</h1>
870+
<pre class="prettyprint lang-proto" id="proto"
871+
>message SearchRequest {
872+
required string query = 1;
873+
optional int32 page_number = 2;
874+
optional int32 result_per_page = 3 [default = 10];
875+
enum Corpus {
876+
UNIVERSAL = 0;
877+
WEB = 1;
878+
IMAGES = 2;
879+
LOCAL = 3;
880+
NEWS = 4;
881+
PRODUCTS = 5;
882+
VIDEO = 6;
883+
}
884+
optional Corpus corpus = 4 [default = UNIVERSAL];
885+
}</pre>
886+
867887
</body>
868888

869889
<script type="text/javascript">
@@ -1999,9 +2019,38 @@ <h1>Bug 45 - Square brackets in strings</h1>
19992019
'&nbsp; &nbsp;`END`CLO)`END`PLN<br>' +
20002020
'`END`CLO)`END'),
20012021
issue45: (
2002-
'`KWDthrow`END`PLN `END`KWDnew`END`PLN `END`TYPRuntimeException`END`PUN(`END`STR"Element ["`END`PLN `END`PUN+`END`PLN element`END`PUN.`END`PLNgetName`END`PUN()`END`PLN `END`PUN+`END`PLN <br>' +
2022+
'`KWDthrow`END`PLN `END`KWDnew`END`PLN `END`TYPRuntimeException`END' +
2023+
'`PUN(`END`STR"Element ["`END`PLN `END`PUN+`END`PLN element`END' +
2024+
'`PUN.`END`PLNgetName`END`PUN()`END`PLN `END`PUN+`END`PLN <br>' +
20032025
'&nbsp; `END`STR"] missing attribute."`END`PUN);`END`PLN<br>' +
2004-
'variable`END`PUN++;`END')
2026+
'variable`END`PUN++;`END'),
2027+
proto: (
2028+
'`KWDmessage`END`PLN `END`TYPSearchRequest`END`PLN `END`PUN{`END' +
2029+
'`PLN<br>' +
2030+
'&nbsp; `END`KWDrequired`END`PLN `END`KWDstring`END`PLN query `END' +
2031+
'`PUN=`END`PLN `END`LIT1`END`PUN;`END`PLN<br>' +
2032+
'&nbsp; `END`KWDoptional`END`PLN `END`KWDint32`END`PLN page_number `END' +
2033+
'`PUN=`END`PLN `END`LIT2`END`PUN;`END`PLN<br>' +
2034+
'&nbsp; `END`KWDoptional`END`PLN `END`KWDint32`END' +
2035+
'`PLN result_per_page `END`PUN=`END`PLN `END`LIT3`END`PLN `END' +
2036+
'`PUN[`END`KWDdefault`END`PLN `END`PUN=`END`PLN `END`LIT10`END' +
2037+
'`PUN];`END`PLN<br>' +
2038+
'&nbsp; `END`KWDenum`END`PLN `END`TYPCorpus`END`PLN `END`PUN{`END' +
2039+
'`PLN<br>' +
2040+
'&nbsp; &nbsp; UNIVERSAL `END`PUN=`END`PLN `END`LIT0`END`PUN;`END' +
2041+
'`PLN<br>' +
2042+
'&nbsp; &nbsp; WEB `END`PUN=`END`PLN `END`LIT1`END`PUN;`END`PLN<br>' +
2043+
'&nbsp; &nbsp; IMAGES `END`PUN=`END`PLN `END`LIT2`END`PUN;`END`PLN<br>' +
2044+
'&nbsp; &nbsp; LOCAL `END`PUN=`END`PLN `END`LIT3`END`PUN;`END`PLN<br>' +
2045+
'&nbsp; &nbsp; NEWS `END`PUN=`END`PLN `END`LIT4`END`PUN;`END`PLN<br>' +
2046+
'&nbsp; &nbsp; PRODUCTS `END`PUN=`END`PLN `END`LIT5`END`PUN;`END' +
2047+
'`PLN<br>' +
2048+
'&nbsp; &nbsp; VIDEO `END`PUN=`END`PLN `END`LIT6`END`PUN;`END`PLN<br>' +
2049+
'&nbsp; `END`PUN}`END`PLN<br>' +
2050+
'&nbsp; `END`KWDoptional`END`PLN `END`TYPCorpus`END`PLN corpus `END' +
2051+
'`PUN=`END`PLN `END`LIT4`END`PLN `END`PUN[`END`KWDdefault`END' +
2052+
'`PLN `END`PUN=`END`PLN UNIVERSAL`END`PUN];`END`PLN<br>' +
2053+
'`END`PUN}`END')
20052054
};
20062055

20072056

0 commit comments

Comments
 (0)