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

Commit 42629ce

Browse files
bug 90: added rule to distinguish C preprocessor directives from comments
1 parent 7262a86 commit 42629ce

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/prettify.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,8 +952,12 @@ window['_pr_isIE6'] = function () {
952952
if (options['cStyleComments']) {
953953
// Stop C preprocessor declarations at an unclosed open comment
954954
shortcutStylePatterns.push(
955-
[PR_COMMENT, /^#(?:[^\r\n\/]|\/(?!\*)|\/\*[^\r\n]*?\*\/)*/,
955+
[PR_COMMENT, /^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\r\n]*)/,
956956
null, '#']);
957+
fallthroughStylePatterns.push(
958+
[PR_STRING,
959+
/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,
960+
null]);
957961
} else {
958962
shortcutStylePatterns.push([PR_COMMENT, /^#[^\r\n]*/, null, '#']);
959963
}

tests/prettify_test.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ <h1>Issue 93 -- C# verbatim strings</h1>
11271127
'`PUN/*`END`PLNhead `END`PUN-`END`LIT10`END`PLN `END`PUN|`END' +
11281128
'`PLN tail `END`PUN-`END`LIT1`END'),
11291129
C: (
1130-
'`COM#include &lt;stdio.h&gt;`END`PLN<br>' +
1130+
'`COM#include`END`PLN `END`STR&lt;stdio.h&gt;`END`PLN<br>' +
11311131
'<br>' +
11321132
'`END`COM/* the n-th fibonacci number.<br>' +
11331133
'&nbsp;*\/`END`PLN<br>' +
@@ -1153,7 +1153,7 @@ <h1>Issue 93 -- C# verbatim strings</h1>
11531153
'`LIT10`END`PUN));`END`PLN<br>' +
11541154
'`END`PUN}`END'),
11551155
C_lang: (
1156-
'`COM#include &lt;stdio.h&gt;`END`PLN<br>' +
1156+
'`COM#include`END`PLN `END`STR&lt;stdio.h&gt;`END`PLN<br>' +
11571157
'<br>' +
11581158
'`END`COM/* the n`END<sup>`COMth`END<\/sup>`COM fibonacci number. *\/`END`PLN<br>' +
11591159
'`END`KWDunsigned`END`PLN `END`KWDint`END`PLN fib`END`PUN(`END' +
@@ -1178,10 +1178,10 @@ <h1>Issue 93 -- C# verbatim strings</h1>
11781178
'`LIT10`END`PUN));`END`PLN<br>' +
11791179
'`END`PUN}`END`PLN<br>' +
11801180
'<br>' +
1181-
'`END`COM#define ZERO 0 /* a<br>' +
1181+
'`END`COM#define`END`PLN ZERO `END`LIT0`END`PLN `END`COM/* a<br>' +
11821182
'&nbsp; multiline comment */`END'),
11831183
Cpp: (
1184-
'`COM#include &lt;iostream&gt;`END`PLN<br>' +
1184+
'`COM#include`END`PLN `END`STR&lt;iostream&gt;`END`PLN<br>' +
11851185
'<br>' +
11861186
'`END`KWDusing`END`PLN `END`KWDnamespace`END`PLN std`END`PUN;`END' +
11871187
'`PLN<br>' +
@@ -1216,7 +1216,7 @@ <h1>Issue 93 -- C# verbatim strings</h1>
12161216
'`END`PUN}`END'),
12171217

12181218
Cpp_lang: (
1219-
'`COM#include &lt;iostream&gt;`END`PLN<br>' +
1219+
'`COM#include`END`PLN `END`STR&lt;iostream&gt;`END`PLN<br>' +
12201220
'<br>' +
12211221
'`END`KWDusing`END`PLN `END`KWDnamespace`END`PLN std`END`PUN;`END' +
12221222
'`PLN<br>' +

0 commit comments

Comments
 (0)