VSCode tmLanguage.json issue: how to prevent nested block comment?

Viewed 61

I want to support a customized language which does not support nested block comment, i.e., the following code should be considered as comment:

/* /*  */

The tmLanguage.json for my VSCode extension uses:

  "comment": "Block comment",
  "name": "comment.block.cxm",
  "begin": "/\\*",
  "end": "\\*/",

It failed and it requires another "*/" to end the comment. I tried

  "begin": "/\\*[\\s\\S]*(?=\\*/)",

it works for the above code, but it can't handle multi-line case:

/*
/*
*/

Can any one help? Thanks!

1 Answers

After some researching in TextMate, the tmLanguage.json defaultly does not support nested pattern. I incorrectly used:

"block_comment": {
    "comment": "Block comment",
    "name": "comment.block.cxm",
    "begin": "/\\*",
    "end": "\\*/",
    "patterns": [
    {
        "include": "#block_comment"
    }
}

I removed the "patterns" field and now the nested block comment is not allowed.

Related