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

Commit 7ab5d68

Browse files
author
mikesamuel@gmail.com
committed
bug 93: support for C# verbatim strings
1 parent 82be2f2 commit 7ab5d68

2 files changed

Lines changed: 27 additions & 9 deletions

File tree

src/prettify.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,11 @@ window['_pr_isIE6'] = function () {
943943
/^(?:\'(?:[^\\\'\r\n]|\\.)*(?:\'|$)|\"(?:[^\\\"\r\n]|\\.)*(?:\"|$))/,
944944
null, '"\'']);
945945
}
946+
if (options['verbatimStrings']) {
947+
// verbatim-string-literal production from the C# grammar. See issue 93.
948+
fallthroughStylePatterns.push(
949+
[PR_STRING, /^@\"(?:[^\"]|\"\")*(?:\"|$)/, null]);
950+
}
946951
if (options['hashComments']) {
947952
if (options['cStyleComments']) {
948953
// Stop C preprocessor declarations at an unclosed open comment
@@ -988,7 +993,7 @@ window['_pr_isIE6'] = function () {
988993
shortcutStylePatterns.push([PR_PLAIN, /^\s+/, null, ' \r\n\t\xA0']);
989994
fallthroughStylePatterns.push(
990995
// TODO(mikesamuel): recognize non-latin letters and numerals in idents
991-
[PR_LITERAL, /^@[a-z_$][a-z_$@0-9]*/i, null, '@'],
996+
[PR_LITERAL, /^@[a-z_$][a-z_$@0-9]*/i, null],
992997
[PR_TYPE, /^@?[A-Z]+[a-z][A-Za-z_$@0-9]*/, null],
993998
[PR_PLAIN, /^[a-z_$][a-z_$@0-9]*/i, null],
994999
[PR_LITERAL,
@@ -1218,7 +1223,8 @@ window['_pr_isIE6'] = function () {
12181223
registerLangHandler(sourceDecorator({
12191224
'keywords': CSHARP_KEYWORDS,
12201225
'hashComments': true,
1221-
'cStyleComments': true
1226+
'cStyleComments': true,
1227+
'verbatimStrings': true
12221228
}), ['cs']);
12231229
registerLangHandler(sourceDecorator({
12241230
'keywords': JAVA_KEYWORDS,

tests/prettify_test.html

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ <h1>Issue 86</h1>
10501050
<p><code class="prettyprint" id="issue86_5">#One<br>
10511051
Two lines</code></p>
10521052

1053-
<h1>Issue 92</h1>
1053+
<h1>Issue 92 -- capital letters in tag names</h1>
10541054
<pre class="prettyprint" id="issue92">
10551055
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
10561056
&lt;kml xmlns="http://www.opengis.net/kml/2.2"&gt;
@@ -1064,6 +1064,14 @@ <h1>Issue 92</h1>
10641064
&lt;/Placemark&gt;
10651065
&lt;/kml&gt;
10661066
</pre>
1067+
1068+
<h1>Issue 93 -- C# verbatim strings</h1>
1069+
<pre class="prettyprint lang-cs" id="issue93">
1070+
// The normal string syntax
1071+
string a = "C:\\";
1072+
// is equivalent to a verbatim string
1073+
string b = @"C:\";
1074+
</pre>
10671075
</body>
10681076

10691077
<script type="text/javascript">
@@ -2438,22 +2446,26 @@ <h1>Issue 92</h1>
24382446
'`END`TYPTwo`END`PLN lines`END',
24392447
issue86_4: '`COM#One`END`PLN<br>' +
24402448
'`END`TYPTwo`END`PLN lines`END',
2441-
issue92: '`PUN&lt;?`END`PLNxml version`END`PUN=`END`STR"1.0"`END`PLN encoding`END`PUN=`END ' +
2449+
issue92: '`PUN&lt;?`END`PLNxml version`END`PUN=`END`STR"1.0"`END`PLN encoding`END`PUN=`END' +
24422450
'`STR"UTF-8"`END`PUN?&gt;`END`PLN<br>' +
2443-
'`END`TAG&lt;kml`END`PLN `END`ATNxmlns`END`PUN=`END`ATV"http://www.opengis.net/kml/2.2"`END ' +
2451+
'`END`TAG&lt;kml`END`PLN `END`ATNxmlns`END`PUN=`END`ATV"http://www.opengis.net/kml/2.2"`END' +
24442452
'`TAG&gt;`END`PLN<br>' +
24452453
'&nbsp; `END`TAG&lt;Placemark&gt;`END`PLN<br>' +
24462454
'&nbsp; &nbsp; `END`TAG&lt;name&gt;`END`PLNSimple placemark`END`TAG&lt;/name&gt;`END`PLN<br>' +
2447-
'&nbsp; &nbsp; `END`TAG&lt;description&gt;`END`PLNAttached to the ground. ' +
2455+
'&nbsp; &nbsp; `END`TAG&lt;description&gt;`END`PLNAttached to the ground.' +
24482456
' Intelligently places itself <br>' +
2449-
'&nbsp; &nbsp; &nbsp; &nbsp;at the height of the underlying terrain.`END ' +
2457+
'&nbsp; &nbsp; &nbsp; &nbsp;at the height of the underlying terrain.`END' +
24502458
'`TAG&lt;/description&gt;`END`PLN<br>' +
24512459
'&nbsp; &nbsp; `END`TAG&lt;Point&gt;`END`PLN<br>' +
2452-
'&nbsp; &nbsp; &nbsp; `END`TAG&lt;coordinates&gt;`END ' +
2460+
'&nbsp; &nbsp; &nbsp; `END`TAG&lt;coordinates&gt;`END' +
24532461
'`PLN-122.0822035425683,37.42228990140251,0`END`TAG&lt;/coordinates&gt;`END`PLN<br>' +
24542462
'&nbsp; &nbsp; `END`TAG&lt;/Point&gt;`END`PLN<br>' +
24552463
'&nbsp; `END`TAG&lt;/Placemark&gt;`END`PLN<br>' +
2456-
'`END`TAG&lt;/kml&gt;`END'
2464+
'`END`TAG&lt;/kml&gt;`END',
2465+
issue93: '`COM// The normal string syntax`END`PLN<br>' +
2466+
'`END`KWDstring`END`PLN a `END`PUN=`END`PLN `END`STR"C:\\\\"`END`PUN;`END`PLN<br>' +
2467+
'`END`COM// is equivalent to a verbatim string`END`PLN<br>' +
2468+
'`END`KWDstring`END`PLN b `END`PUN=`END`PLN `END`STR@"C:\\"`END`PUN;`END'
24572469
};
24582470
</script>
24592471

0 commit comments

Comments
 (0)