Skip to content

Commit

Permalink
Improve detection of C block comments
Browse files Browse the repository at this point in the history
Illegalized `/*` in a bunch of languages and added some new phrasal
words to comments. This was prompted by a real example in
https://meta.discourse.org/t/code-fences-dont-seem-to-deal-with-c-comments/33339
which is now stored as a detection test for C++ in
test/detect/cpp/comments.txt.

Fixes #937.
  • Loading branch information
isagalaev committed Sep 17, 2015
1 parent 4940b22 commit 266e03e
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/highlight.js
Expand Up @@ -693,7 +693,7 @@ https://highlightjs.org/
contains: [hljs.BACKSLASH_ESCAPE]
};
hljs.PHRASAL_WORDS_MODE = {
begin: /\b(a|an|the|are|I|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such)\b/
begin: /\b(a|an|the|are|I|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|like)\b/
};
hljs.COMMENT = function (begin, end, inherits) {
var mode = hljs.inherit(
Expand Down
1 change: 1 addition & 0 deletions src/languages/autoit.js
Expand Up @@ -1742,6 +1742,7 @@ function(hljs) {

return {
case_insensitive: true,
illegal: /\/\*/,
keywords: {
keyword: KEYWORDS,
built_in: BUILT_IN,
Expand Down
1 change: 1 addition & 0 deletions src/languages/cal.js
Expand Up @@ -73,6 +73,7 @@ function(hljs) {
return {
case_insensitive: true,
keywords: { keyword: KEYWORDS, literal: LITERALS },
illegal: /\/\*/,
contains: [
STRING, CHAR_STRING,
DATE, DBL_QUOTED_VARIABLE,
Expand Down
1 change: 1 addition & 0 deletions src/languages/dos.js
Expand Up @@ -19,6 +19,7 @@ function(hljs) {
return {
aliases: ['bat', 'cmd'],
case_insensitive: true,
illegal: /\/\*/,
keywords: {
flow: 'if else goto for in do call exit not exist errorlevel defined',
operator: 'equ neq lss leq gtr geq',
Expand Down
1 change: 1 addition & 0 deletions src/languages/fortran.js
Expand Up @@ -55,6 +55,7 @@ function(hljs) {
case_insensitive: true,
aliases: ['f90', 'f95'],
keywords: F_KEYWORDS,
illegal: /\/\*/,
contains: [
hljs.inherit(hljs.APOS_STRING_MODE, {className: 'string', relevance: 0}),
hljs.inherit(hljs.QUOTE_STRING_MODE, {className: 'string', relevance: 0}),
Expand Down
1 change: 1 addition & 0 deletions src/languages/fsharp.js
Expand Up @@ -21,6 +21,7 @@ function(hljs) {
'match member module mutable namespace new null of open or ' +
'override private public rec return sig static struct then to ' +
'true try type upcast use val void when while with yield',
illegal: /\/\*/,
contains: [
{
// monad builder keywords (matches before non-bang kws)
Expand Down
3 changes: 2 additions & 1 deletion src/languages/irpf90.js
Expand Up @@ -59,7 +59,8 @@ function(hljs) {
};
return {
case_insensitive: true,
keywords: F_KEYWORDS,
keywords: F_KEYWORDS,
illegal: /\/\*/,
contains: [
hljs.inherit(hljs.APOS_STRING_MODE, {className: 'string', relevance: 0}),
hljs.inherit(hljs.QUOTE_STRING_MODE, {className: 'string', relevance: 0}),
Expand Down
1 change: 1 addition & 0 deletions src/languages/monkey.js
Expand Up @@ -26,6 +26,7 @@ function(hljs) {

literal: 'true false null and or shl shr mod'
},
illegal: /\/\*/,
contains: [
hljs.COMMENT('#rem', '#end'),
hljs.COMMENT(
Expand Down
1 change: 1 addition & 0 deletions src/languages/ruby.js
Expand Up @@ -170,6 +170,7 @@ function(hljs) {
return {
aliases: ['rb', 'gemspec', 'podspec', 'thor', 'irb'],
keywords: RUBY_KEYWORDS,
illegal: /\/\*/,
contains: COMMENT_MODES.concat(IRB_DEFAULT).concat(RUBY_DEFAULT_CONTAINS)
};
}
16 changes: 16 additions & 0 deletions test/detect/cpp/comment.txt
@@ -0,0 +1,16 @@
/*
To use this program, compile it -- if you can -- and then type something like:

chan -n 5000 -d 2 < input.txt

In this case, it will produce 5000 words of output, checking two-word groups.
(The explanation above describes two-word generation. If you type "-d 3",
the program will find three-word groups, and so on. Greater depths make more
sense, but they require more input text and take more time to process.)

http://www.eblong.com/zarf/markov/
*/


/* make cpp win deterministically over others with C block comments */
cout << endl;

0 comments on commit 266e03e

Please sign in to comment.