diff --git a/grammar.js b/grammar.js index 114b847..2364a5a 100644 --- a/grammar.js +++ b/grammar.js @@ -190,6 +190,8 @@ module.exports = grammar({ choice( "shape", "label", + "link", + "tooltip", // sql "constraint", // image diff --git a/src/grammar.json b/src/grammar.json index 3aa6922..dc01220 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -777,6 +777,14 @@ "type": "STRING", "value": "label" }, + { + "type": "STRING", + "value": "link" + }, + { + "type": "STRING", + "value": "tooltip" + }, { "type": "STRING", "value": "constraint" @@ -1286,14 +1294,26 @@ } }, "_unquoted_string": { - "type": "TOKEN", + "type": "REPEAT1", "content": { - "type": "PREC", - "value": -1, - "content": { - "type": "PATTERN", - "value": "[^'\"`|\\n\\s;{}]([^\\n;{}]*[^\\n\\s;{}])?" - } + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "escape_sequence" + }, + { + "type": "TOKEN", + "content": { + "type": "PREC", + "value": -1, + "content": { + "type": "PATTERN", + "value": "[^'\"`\\\\|\\n\\s;{}]([^\\\\\\n;{}]*[^\\\\\\n\\s;{}])?" + } + } + } + ] } }, "string": { diff --git a/src/node-types.json b/src/node-types.json index 15a9534..92c1eec 100644 --- a/src/node-types.json +++ b/src/node-types.json @@ -19,13 +19,17 @@ "named": true, "fields": {}, "children": { - "multiple": false, + "multiple": true, "required": false, "types": [ { "type": "boolean", "named": true }, + { + "type": "escape_sequence", + "named": true + }, { "type": "float", "named": true @@ -202,9 +206,13 @@ "named": true, "fields": {}, "children": { - "multiple": false, + "multiple": true, "required": false, "types": [ + { + "type": "escape_sequence", + "named": true + }, { "type": "string", "named": true @@ -476,6 +484,10 @@ "type": "target-arrowhead", "named": false }, + { + "type": "tooltip", + "named": false + }, { "type": "true", "named": false diff --git a/src/parser.c b/src/parser.c index 2c3ba0a..334c028 100644 Binary files a/src/parser.c and b/src/parser.c differ diff --git a/test/corpus/attributes.txt b/test/corpus/attributes.txt index b38f8bd..0aba8d6 100644 --- a/test/corpus/attributes.txt +++ b/test/corpus/attributes.txt @@ -125,6 +125,8 @@ foo: { icon: pathto width: 100 height: 200 + link: https://microsoft.com + tooltip: Gee, I feel kind of LIGHT in the head now,\nknowing I can't make my satellite dish PAYMENTS! } -------------------------------------------------------------------------------- @@ -139,6 +141,8 @@ foo: { (attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value (integer))) (attribute (attr_key) (attr_value (integer))) + (attribute (attr_key) (attr_value)) + (attribute (attr_key) (attr_value (escape_sequence))) ) ) ) diff --git a/test/corpus/shape.txt b/test/corpus/shape.txt index a0e25b5..54b87da 100644 --- a/test/corpus/shape.txt +++ b/test/corpus/shape.txt @@ -103,6 +103,21 @@ a: Foo Bar; b: Biz Baz (shape (shape_key) (label)) ) +================================================================================ +Label with escape sequence +================================================================================ +a: Foo\nB\#ar +a: Foo\nB\@r; b: Biz\nBaz + +-------------------------------------------------------------------------------- + +(source_file + (shape (shape_key) (label (escape_sequence) (escape_sequence))) + (shape (shape_key) (label (escape_sequence) (escape_sequence))) + (shape (shape_key) (label (escape_sequence))) +) + + ================================================================================ It should skip white spaces ================================================================================ diff --git a/test/highlight/attribute.d2 b/test/highlight/attribute.d2 index f870e2f..3dfd5a2 100644 --- a/test/highlight/attribute.d2 +++ b/test/highlight/attribute.d2 @@ -26,7 +26,6 @@ foo: Label { # ^ property } - foo: { style: { opacity: 0.5 @@ -43,3 +42,18 @@ foo: { # ^ boolean } } + +foo: Label { + tooltip: Gee, I feel kind of LIGHT in the head now,\nknowing I can't make my satellite dish PAYMENTS! + # <- property + # ^ string + # ^ string.escape + + link: https://microsoft.com + # <- property + # ^ string + + style.fill: red + # <- property + # ^ property +} diff --git a/test/highlight/shape.d2 b/test/highlight/shape.d2 index 6b7c6a8..d74ba02 100644 --- a/test/highlight/shape.d2 +++ b/test/highlight/shape.d2 @@ -35,3 +35,10 @@ foo: Foo Bar { # ^ variable } # <- punctuation.bracket + +foo: Foo\#Ba\@r { + # ^ text.title + # ^ string.escape + # ^ text.title + # ^ string.escape +} diff --git a/tree-sitter-d2.wasm b/tree-sitter-d2.wasm index 501a657..9de2e30 100755 Binary files a/tree-sitter-d2.wasm and b/tree-sitter-d2.wasm differ