summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/parse/tokens.rs4
-rw-r--r--tests/ref/code/comment.pngbin2585 -> 2648 bytes
-rw-r--r--tests/typ/code/comment.typ12
-rw-r--r--tools/support/typst.tmLanguage.json23
4 files changed, 27 insertions, 12 deletions
diff --git a/src/parse/tokens.rs b/src/parse/tokens.rs
index e004dd37..67d413fd 100644
--- a/src/parse/tokens.rs
+++ b/src/parse/tokens.rs
@@ -591,6 +591,10 @@ impl<'s> Tokens<'s> {
depth += 1;
'_'
}
+ ('/', '/') => {
+ self.line_comment();
+ '_'
+ }
_ => c,
}
}
diff --git a/tests/ref/code/comment.png b/tests/ref/code/comment.png
index d7b59976..b1c630a9 100644
--- a/tests/ref/code/comment.png
+++ b/tests/ref/code/comment.png
Binary files differ
diff --git a/tests/typ/code/comment.typ b/tests/typ/code/comment.typ
index 407bebd4..db0a17a4 100644
--- a/tests/typ/code/comment.typ
+++ b/tests/typ/code/comment.typ
@@ -5,7 +5,7 @@
A// you
B
-// Block comment does not act as spacing.
+// Block comment does not act as spacing, nested block comments.
C/*
/* */
*/D
@@ -14,6 +14,16 @@ C/*
#test(type(/*1*/ 1) //
, "integer")
+// End of block comment in line comment.
+// Hello */
+
+// Nested line comment.
+/*//*/
+Still comment.
+*/
+
+E
+
---
// Line comments have a special case for URLs.
https://example.com \
diff --git a/tools/support/typst.tmLanguage.json b/tools/support/typst.tmLanguage.json
index 36ffade7..f493cc5b 100644
--- a/tools/support/typst.tmLanguage.json
+++ b/tools/support/typst.tmLanguage.json
@@ -4,20 +4,27 @@
{ "include": "#markup" }
],
"repository": {
- "blockcomment": {
+ "comments": {
"patterns": [
{
"name": "comment.block.typst",
"begin": "/\\*",
"end": "\\*/",
"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": {
"patterns": [
- { "include": "#blockcomment" },
+ { "include": "#comments" },
{
"name": "meta.block.code.typst",
"begin": "{",
@@ -38,12 +45,6 @@
"patterns": [
{ "include": "#common" },
{
- "name": "comment.line.double-slash.typst",
- "begin": "(?<!:)//",
- "end": "\n",
- "beginCaptures": { "0": { "name": "punctuation.definition.comment.typst" } }
- },
- {
"name": "constant.character.escape.content.typst",
"match": "\\\\([\\\\/\\[\\]{}#*_=~`$-.]|u\\{[0-9a-zA-Z]*\\}?)"
},
@@ -128,7 +129,7 @@
"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|(;)|(?=])",
"beginCaptures": {
"0": { "name": "keyword.other.typst" },
@@ -239,7 +240,7 @@
},
{
"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",