Skip to content

Commit

Permalink
C/C++: Improvemed comment pattern (#2229)
Browse files Browse the repository at this point in the history
This improves the `comment` pattern by allowing backslash-escaped line breaks in single-line comments.
  • Loading branch information
RunDevelopment authored Feb 24, 2020
1 parent 73c8a37 commit fa63072
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 1 deletion.
4 changes: 4 additions & 0 deletions components/prism-c.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
Prism.languages.c = Prism.languages.extend('clike', {
'comment': {
pattern: /\/\/(?:[^\r\n\\]|\\(?:\r\n?|\n|(?![\r\n])))*|\/\*[\s\S]*?(?:\*\/|$)/,
greedy: true
},
'class-name': {
pattern: /(\b(?:enum|struct)\s+(?:__attribute__\s*\(\([\s\S]*?\)\)\s*)?)\w+/,
lookbehind: true
Expand Down
2 changes: 1 addition & 1 deletion components/prism-c.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions tests/languages/c/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// comment
// the comment \
continues!

/**/
/*
* comment
*/

/* open-ended comment

----------------------------------------------------

[
["comment", "//"],
["comment", "// comment"],
["comment", "// the comment \\\r\n continues!"],
["comment", "/**/"],
["comment", "/*\r\n * comment\r\n */"],
["comment", "/* open-ended comment"]
]

----------------------------------------------------

Checks for comments.
26 changes: 26 additions & 0 deletions tests/languages/cpp/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// comment
// the comment \
continues!

/**/
/*
* comment
*/

/* open-ended comment

----------------------------------------------------

[
["comment", "//"],
["comment", "// comment"],
["comment", "// the comment \\\r\n continues!"],
["comment", "/**/"],
["comment", "/*\r\n * comment\r\n */"],
["comment", "/* open-ended comment"]
]

----------------------------------------------------

Checks for comments.
26 changes: 26 additions & 0 deletions tests/languages/objectivec/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// comment
// the comment \
continues!

/**/
/*
* comment
*/

/* open-ended comment

----------------------------------------------------

[
["comment", "//"],
["comment", "// comment"],
["comment", "// the comment \\\r\n continues!"],
["comment", "/**/"],
["comment", "/*\r\n * comment\r\n */"],
["comment", "/* open-ended comment"]
]

----------------------------------------------------

Checks for comments.

0 comments on commit fa63072

Please sign in to comment.