diff --git a/grammar.js b/grammar.js index 249e32d..50b01d1 100644 --- a/grammar.js +++ b/grammar.js @@ -3,7 +3,7 @@ const spaces = repeat(" "); module.exports = grammar({ name: "d2", - extras: ($) => [], + extras: ($) => [$.line_comment], word: ($) => $._word, @@ -175,6 +175,8 @@ module.exports = grammar({ seq("`", repeat(token.immediate(/[^`\n]+/)), "`") ), + line_comment: ($) => token(seq("#", /.*/)), + _word: ($) => /[\w\d]+/, _emptyline: ($) => seq(spaces, $._eof), diff --git a/queries/highlights.scm b/queries/highlights.scm index 4c9af68..8c5a0cf 100644 --- a/queries/highlights.scm +++ b/queries/highlights.scm @@ -3,12 +3,19 @@ (identifier) @variable (attr_key) @keyword +; Literals ;------------------------------------------------------------------------------- (string) @string (label) @string (attr_value) @string +; Comments +;------------------------------------------------------------------------------- + +(line_comment) @comment.line + +; Punctiation ;------------------------------------------------------------------------------- (arrow) @operator diff --git a/src/grammar.json b/src/grammar.json index ae3699a..bcf8222 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -969,6 +969,22 @@ } ] }, + "line_comment": { + "type": "TOKEN", + "content": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "#" + }, + { + "type": "PATTERN", + "value": ".*" + } + ] + } + }, "_word": { "type": "PATTERN", "value": "[\\w\\d]+" @@ -1028,7 +1044,12 @@ ] } }, - "extras": [], + "extras": [ + { + "type": "SYMBOL", + "name": "line_comment" + } + ], "conflicts": [ [ "identifier" diff --git a/src/node-types.json b/src/node-types.json index 7d868bf..2152b60 100644 --- a/src/node-types.json +++ b/src/node-types.json @@ -269,6 +269,10 @@ "type": "label", "named": false }, + { + "type": "line_comment", + "named": true + }, { "type": "link", "named": false diff --git a/src/parser.c b/src/parser.c index 00fe788..8c1071c 100644 Binary files a/src/parser.c and b/src/parser.c differ