add comments

This commit is contained in:
Dmitriy Pleshevskiy 2022-12-07 12:09:27 +03:00
parent 1095c58b33
commit b539703965
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
5 changed files with 36 additions and 2 deletions

View file

@ -3,7 +3,7 @@ const spaces = repeat(" ");
module.exports = grammar({ module.exports = grammar({
name: "d2", name: "d2",
extras: ($) => [], extras: ($) => [$.line_comment],
word: ($) => $._word, word: ($) => $._word,
@ -175,6 +175,8 @@ module.exports = grammar({
seq("`", repeat(token.immediate(/[^`\n]+/)), "`") seq("`", repeat(token.immediate(/[^`\n]+/)), "`")
), ),
line_comment: ($) => token(seq("#", /.*/)),
_word: ($) => /[\w\d]+/, _word: ($) => /[\w\d]+/,
_emptyline: ($) => seq(spaces, $._eof), _emptyline: ($) => seq(spaces, $._eof),

View file

@ -3,12 +3,19 @@
(identifier) @variable (identifier) @variable
(attr_key) @keyword (attr_key) @keyword
; Literals
;------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------
(string) @string (string) @string
(label) @string (label) @string
(attr_value) @string (attr_value) @string
; Comments
;-------------------------------------------------------------------------------
(line_comment) @comment.line
; Punctiation
;------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------
(arrow) @operator (arrow) @operator

View file

@ -969,6 +969,22 @@
} }
] ]
}, },
"line_comment": {
"type": "TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "#"
},
{
"type": "PATTERN",
"value": ".*"
}
]
}
},
"_word": { "_word": {
"type": "PATTERN", "type": "PATTERN",
"value": "[\\w\\d]+" "value": "[\\w\\d]+"
@ -1028,7 +1044,12 @@
] ]
} }
}, },
"extras": [], "extras": [
{
"type": "SYMBOL",
"name": "line_comment"
}
],
"conflicts": [ "conflicts": [
[ [
"identifier" "identifier"

View file

@ -269,6 +269,10 @@
"type": "label", "type": "label",
"named": false "named": false
}, },
{
"type": "line_comment",
"named": true
},
{ {
"type": "link", "type": "link",
"named": false "named": false

Binary file not shown.