Handle line comments nested in block comments

Fixes #76
This commit is contained in:
Laurenz 2022-09-19 11:05:25 +02:00
parent a2e25d2dad
commit e5f958b921
4 changed files with 27 additions and 12 deletions

View File

@ -591,6 +591,10 @@ impl<'s> Tokens<'s> {
depth += 1; depth += 1;
'_' '_'
} }
('/', '/') => {
self.line_comment();
'_'
}
_ => c, _ => c,
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

@ -5,7 +5,7 @@
A// you A// you
B B
// Block comment does not act as spacing. // Block comment does not act as spacing, nested block comments.
C/* C/*
/* */ /* */
*/D */D
@ -14,6 +14,16 @@ C/*
#test(type(/*1*/ 1) // #test(type(/*1*/ 1) //
, "integer") , "integer")
// End of block comment in line comment.
// Hello */
// Nested line comment.
/*//*/
Still comment.
*/
E
--- ---
// Line comments have a special case for URLs. // Line comments have a special case for URLs.
https://example.com \ https://example.com \

View File

@ -4,20 +4,27 @@
{ "include": "#markup" } { "include": "#markup" }
], ],
"repository": { "repository": {
"blockcomment": { "comments": {
"patterns": [ "patterns": [
{ {
"name": "comment.block.typst", "name": "comment.block.typst",
"begin": "/\\*", "begin": "/\\*",
"end": "\\*/", "end": "\\*/",
"captures": { "0": { "name": "punctuation.definition.comment.typst" } }, "captures": { "0": { "name": "punctuation.definition.comment.typst" } },
"patterns": [{ "include": "#blockcomment" }] "patterns": [{ "include": "#comments" }]
},
{
"name": "comment.line.double-slash.typst",
"begin": "(?<!:)//",
"end": "\n",
"beginCaptures": { "0": { "name": "punctuation.definition.comment.typst" } },
"patterns": [{ "include": "#comments" }]
} }
] ]
}, },
"common": { "common": {
"patterns": [ "patterns": [
{ "include": "#blockcomment" }, { "include": "#comments" },
{ {
"name": "meta.block.code.typst", "name": "meta.block.code.typst",
"begin": "{", "begin": "{",
@ -37,12 +44,6 @@
"markup": { "markup": {
"patterns": [ "patterns": [
{ "include": "#common" }, { "include": "#common" },
{
"name": "comment.line.double-slash.typst",
"begin": "(?<!:)//",
"end": "\n",
"beginCaptures": { "0": { "name": "punctuation.definition.comment.typst" } }
},
{ {
"name": "constant.character.escape.content.typst", "name": "constant.character.escape.content.typst",
"match": "\\\\([\\\\/\\[\\]{}#*_=~`$-.]|u\\{[0-9a-zA-Z]*\\}?)" "match": "\\\\([\\\\/\\[\\]{}#*_=~`$-.]|u\\{[0-9a-zA-Z]*\\}?)"
@ -128,7 +129,7 @@
"captures": { "1": { "name": "punctuation.definition.label.typst" } } "captures": { "1": { "name": "punctuation.definition.label.typst" } }
}, },
{ {
"begin": "(#)(pub|let|set|rule|select|show|wrap)\\b", "begin": "(#)(pub|let|set|show|wrap)\\b",
"end": "\n|(;)|(?=])", "end": "\n|(;)|(?=])",
"beginCaptures": { "beginCaptures": {
"0": { "name": "keyword.other.typst" }, "0": { "name": "keyword.other.typst" },
@ -239,7 +240,7 @@
}, },
{ {
"name": "keyword.other.typst", "name": "keyword.other.typst",
"match": "\\b(pub|let|set|rule|select|show|wrap|as|in|from)\\b" "match": "\\b(pub|let|set|show|wrap|as|in|from)\\b"
}, },
{ {
"name": "keyword.control.conditional.typst", "name": "keyword.control.conditional.typst",