grammar: add link and tooltip attributes

Closes #18
This commit is contained in:
Dmitriy Pleshevskiy 2023-01-05 16:53:32 +03:00
parent 32b1fa5555
commit 6a04387009
Signed by: pleshevskiy
GPG Key ID: 1B59187B161C0215
9 changed files with 84 additions and 10 deletions

View File

@ -190,6 +190,8 @@ module.exports = grammar({
choice( choice(
"shape", "shape",
"label", "label",
"link",
"tooltip",
// sql // sql
"constraint", "constraint",
// image // image

View File

@ -777,6 +777,14 @@
"type": "STRING", "type": "STRING",
"value": "label" "value": "label"
}, },
{
"type": "STRING",
"value": "link"
},
{
"type": "STRING",
"value": "tooltip"
},
{ {
"type": "STRING", "type": "STRING",
"value": "constraint" "value": "constraint"
@ -1286,14 +1294,26 @@
} }
}, },
"_unquoted_string": { "_unquoted_string": {
"type": "TOKEN", "type": "REPEAT1",
"content": { "content": {
"type": "PREC", "type": "CHOICE",
"value": -1, "members": [
"content": { {
"type": "PATTERN", "type": "SYMBOL",
"value": "[^'\"`|\\n\\s;{}]([^\\n;{}]*[^\\n\\s;{}])?" "name": "escape_sequence"
} },
{
"type": "TOKEN",
"content": {
"type": "PREC",
"value": -1,
"content": {
"type": "PATTERN",
"value": "[^'\"`\\\\|\\n\\s;{}]([^\\\\\\n;{}]*[^\\\\\\n\\s;{}])?"
}
}
}
]
} }
}, },
"string": { "string": {

View File

@ -19,13 +19,17 @@
"named": true, "named": true,
"fields": {}, "fields": {},
"children": { "children": {
"multiple": false, "multiple": true,
"required": false, "required": false,
"types": [ "types": [
{ {
"type": "boolean", "type": "boolean",
"named": true "named": true
}, },
{
"type": "escape_sequence",
"named": true
},
{ {
"type": "float", "type": "float",
"named": true "named": true
@ -202,9 +206,13 @@
"named": true, "named": true,
"fields": {}, "fields": {},
"children": { "children": {
"multiple": false, "multiple": true,
"required": false, "required": false,
"types": [ "types": [
{
"type": "escape_sequence",
"named": true
},
{ {
"type": "string", "type": "string",
"named": true "named": true
@ -476,6 +484,10 @@
"type": "target-arrowhead", "type": "target-arrowhead",
"named": false "named": false
}, },
{
"type": "tooltip",
"named": false
},
{ {
"type": "true", "type": "true",
"named": false "named": false

Binary file not shown.

View File

@ -125,6 +125,8 @@ foo: {
icon: pathto icon: pathto
width: 100 width: 100
height: 200 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))
(attribute (attr_key) (attr_value (integer))) (attribute (attr_key) (attr_value (integer)))
(attribute (attr_key) (attr_value (integer))) (attribute (attr_key) (attr_value (integer)))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value (escape_sequence)))
) )
) )
) )

View File

@ -103,6 +103,21 @@ a: Foo Bar; b: Biz Baz
(shape (shape_key) (label)) (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 It should skip white spaces
================================================================================ ================================================================================

View File

@ -26,7 +26,6 @@ foo: Label {
# ^ property # ^ property
} }
foo: { foo: {
style: { style: {
opacity: 0.5 opacity: 0.5
@ -43,3 +42,18 @@ foo: {
# ^ boolean # ^ 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
}

View File

@ -35,3 +35,10 @@ foo: Foo Bar {
# ^ variable # ^ variable
} }
# <- punctuation.bracket # <- punctuation.bracket
foo: Foo\#Ba\@r {
# ^ text.title
# ^ string.escape
# ^ text.title
# ^ string.escape
}

Binary file not shown.