Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

block comment decorator added #334

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 22 additions & 17 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class Parser {
private delimiter: string = "";
private blockCommentStart: string = "";
private blockCommentEnd: string = "";
private blockCommentDecorator: string = "";

private highlightSingleLineComments = true;
private highlightMultilineComments = false;
Expand Down Expand Up @@ -135,7 +136,7 @@ export class Parser {
}

// Combine custom delimiters and the rest of the comment block matcher
let commentMatchString = "(^)+([ \\t]*[ \\t]*)(";
let commentMatchString = "(^)+([ \\t]*[ \\t" +this.blockCommentDecorator+ "]*)(";
commentMatchString += characters.join("|");
commentMatchString += ")([ ]*|[:])+([^*/][^\\r\\n]*)";

Expand Down Expand Up @@ -247,15 +248,15 @@ export class Parser {
switch (languageCode) {

case "asciidoc":
this.setCommentFormat("//", "////", "////");
this.setCommentFormat("//", "////", "////", "");
break;

case "apex":
case "javascript":
case "javascriptreact":
case "typescript":
case "typescriptreact":
this.setCommentFormat("//", "/*", "*/");
this.setCommentFormat("//", "/*", "*/", "*");
this.highlightJSDoc = true;
break;

Expand Down Expand Up @@ -285,11 +286,11 @@ export class Parser {
case "swift":
case "verilog":
case "vue":
this.setCommentFormat("//", "/*", "*/");
this.setCommentFormat("//", "/*", "*/", "*");
break;

case "css":
this.setCommentFormat("/*", "/*", "*/");
this.setCommentFormat("/*", "/*", "*/", "");
break;

case "coffeescript":
Expand All @@ -316,16 +317,16 @@ export class Parser {

case "elixir":
case "python":
this.setCommentFormat("#", '"""', '"""');
this.setCommentFormat("#", '"""', '"""', "");
this.ignoreFirstLine = true;
break;

case "nim":
this.setCommentFormat("#", "#[", "]#");
this.setCommentFormat("#", "#[", "]#", "");
break;

case "powershell":
this.setCommentFormat("#", "<#", "#>");
this.setCommentFormat("#", "<#", "#>", "");
break;

case "ada":
Expand All @@ -337,12 +338,12 @@ export class Parser {
break;

case "lua":
this.setCommentFormat("--", "--[[", "]]");
this.setCommentFormat("--", "--[[", "]]", "");
break;

case "elm":
case "haskell":
this.setCommentFormat("--", "{-", "-}");
this.setCommentFormat("--", "{-", "-}", "");
break;

case "brightscript":
Expand All @@ -365,7 +366,7 @@ export class Parser {
break;

case "terraform":
this.setCommentFormat("#", "/*", "*/");
this.setCommentFormat("#", "/*", "*/", "");
break;

case "COBOL":
Expand All @@ -378,25 +379,25 @@ export class Parser {

case "SAS":
case "stata":
this.setCommentFormat("*", "/*", "*/");
this.setCommentFormat("*", "/*", "*/", "");
break;

case "html":
case "markdown":
case "xml":
this.setCommentFormat("<!--", "<!--", "-->");
this.setCommentFormat("<!--", "<!--", "-->", "");
break;

case "twig":
this.setCommentFormat("{#", "{#", "#}");
this.setCommentFormat("{#", "{#", "#}", "");
break;

case "genstat":
this.setCommentFormat("\\", '"', '"');
this.setCommentFormat("\\", '"', '"', "");
break;

case "cfml":
this.setCommentFormat("<!---", "<!---", "--->");
this.setCommentFormat("<!---", "<!---", "--->", "");
break;

case "plaintext":
Expand Down Expand Up @@ -463,8 +464,9 @@ export class Parser {
* @param singleLine The single line comment delimiter. If NULL, single line is not supported
* @param start The start delimiter for block comments
* @param end The end delimiter for block comments
* @param decorator The decorator for next line i.e. first character of line
*/
private setCommentFormat(singleLine: string | null, start: string, end: string): void {
private setCommentFormat(singleLine: string | null, start: string, end: string, decorator: string): void {

// If no single line comment delimiter is passed, single line comments are not supported
if (singleLine) {
Expand All @@ -476,6 +478,9 @@ export class Parser {

this.blockCommentStart = this.escapeRegExp(start);
this.blockCommentEnd = this.escapeRegExp(end);
if (decorator) {
this.blockCommentDecorator = this.escapeRegExp(decorator);
}
this.highlightMultilineComments = this.contributions.multilineComments;
}
}