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

Commit 957c268

Browse files
author
mikesamuel
committed
fixed bug: regular expression literal pattern was failing to match certain productions right after the opening slash
1 parent e3afcc9 commit 957c268

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

README.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ <h3>Which languages does it work for?</h3>
7474
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-lisp.js"
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"
77-
><code>LUA</code></a> and <a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-ml.js"
78-
><code>OCAML, SML, and F#</code></a>.
77+
><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
79+
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-sql.js"
80+
><code>SQL</code></a>.
7981

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

src/prettify.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ function pr_isIE6() {
514514
})();
515515

516516
var nPatterns = fallthroughStylePatterns.length;
517+
var notWs = /\S/;
517518

518519
return function (sourceCode, opt_basePos) {
519520
opt_basePos = opt_basePos || 0;
@@ -557,7 +558,7 @@ function pr_isIE6() {
557558
decorations.push(opt_basePos + pos, style);
558559
pos += token.length;
559560
tail = tail.substring(token.length);
560-
if (style !== PR_COMMENT && /\S/.test(token)) { lastToken = token; }
561+
if (style !== PR_COMMENT && notWs.test(token)) { lastToken = token; }
561562
}
562563
return decorations;
563564
};
@@ -677,16 +678,25 @@ function pr_isIE6() {
677678
}
678679
if (options.cStyleComments) {
679680
fallthroughStylePatterns.push([PR_COMMENT, /^\/\/[^\r\n]*/, null]);
680-
}
681-
if (options.regexLiterals) {
682681
fallthroughStylePatterns.push(
683-
[PR_STRING,
684-
/^\/(?:[^\\\*\/\[]|\\[\s\S]|\[(?:[^\]\\]|\\.)*(?:\]|$))+(?:\/|$)/,
685-
REGEXP_PRECEDER_PATTERN]);
682+
[PR_COMMENT, /^\/\*[\s\S]*?(?:\*\/|$)/, null]);
686683
}
687-
if (options.cStyleComments) {
684+
if (options.regexLiterals) {
685+
var REGEX_LITERAL = (
686+
// A regular expression literal starts with a slash that is
687+
// not followed by * or / so that it is not confused with
688+
// comments.
689+
'^/(?=[^/*])'
690+
// and then contains any number of raw characters,
691+
+ '(?:[^/\\x5B\\x5C]'
692+
// escape sequences (\x5C),
693+
+ '|\\x5C[\\s\\S]'
694+
// or non-nesting character sets (\x5B\x5D);
695+
+ '|\\x5B(?:[^\\x5C\\x5D]|\\x5C[\\s\\S])*(?:\\x5D|$))+'
696+
// finally closed by a /.
697+
+ '(?:/|$)');
688698
fallthroughStylePatterns.push(
689-
[PR_COMMENT, /^\/\*[\s\S]*?(?:\*\/|$)/, null]);
699+
[PR_STRING, new RegExp(REGEX_LITERAL), REGEXP_PRECEDER_PATTERN]);
690700
}
691701

692702
var keywords = wordSet(options.keywords);

0 commit comments

Comments
 (0)