add attributes for connections

Closes #5
This commit is contained in:
Dmitriy Pleshevskiy 2022-12-09 14:09:39 +03:00
parent 095dd7d8f3
commit 6ec0bb5c59
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
6 changed files with 491 additions and 44 deletions

View file

@ -46,7 +46,12 @@ module.exports = grammar({
seq( seq(
$._connection_path, $._connection_path,
repeat1(seq($.arrow, $._connection_path)), repeat1(seq($.arrow, $._connection_path)),
optional(seq($._colon, $.label)) optional(
seq(
optional(seq($._colon, optional($.label))),
optional(seq(alias($._connection_block, $.block)))
)
)
), ),
_connection_path: ($) => _connection_path: ($) =>
@ -57,6 +62,12 @@ module.exports = grammar({
$.shape_key $.shape_key
), ),
_connection_block: ($) =>
seq("{", repeat($._connection_block_definition), "}"),
_connection_block_definition: ($) =>
choice($._eol, seq($._connection_attribute, $._end)),
// containers // containers
container: ($) => container: ($) =>
@ -66,14 +77,12 @@ module.exports = grammar({
alias($.shape_key, $.container_key), alias($.shape_key, $.container_key),
choice( choice(
seq($.dot, choice($.shape, $.container)), seq($.dot, choice($.shape, $.container)),
seq(
seq( seq(
optional(seq($._colon, optional($.label))), optional(seq($._colon, optional($.label))),
optional(seq(alias($._container_block, $.block))) optional(seq(alias($._container_block, $.block)))
) )
) )
) )
)
), ),
_container_block: ($) => _container_block: ($) =>
@ -205,7 +214,29 @@ module.exports = grammar({
_text_attr_key: ($) => "near", _text_attr_key: ($) => "near",
_connection_attr_key: ($) => choice("source-arrowhead", "target-arrowhead"), _connection_attribute: ($) =>
choice(
alias($._connection_arrowhead_attribute, $.attribute),
alias($._style_attribute, $.attribute)
),
_connection_arrowhead_attribute: ($) =>
seq(
alias($._connection_arrowhead_attr_key, $.attr_key),
choice(
seq($.dot, alias($._style_attribute, $.attribute)),
seq(
optional(seq($._colon, optional($.label))),
optional(seq(alias($._container_block, $.block)))
)
)
),
_connection_arrowhead_block: ($) =>
seq("{", repeat(choice($._eol, seq($._shape_attribute, $._end))), "}"),
_connection_arrowhead_attr_key: ($) =>
choice("source-arrowhead", "target-arrowhead"),
// //

View file

@ -51,6 +51,10 @@
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_end" "name": "_end"
},
{
"type": "STRING",
"value": "\u0000"
} }
] ]
} }
@ -81,6 +85,12 @@
] ]
} }
}, },
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{ {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
@ -91,9 +101,46 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "_colon" "name": "_colon"
}, },
{
"type": "CHOICE",
"members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "label" "name": "label"
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_connection_block"
},
"named": true,
"value": "block"
}
]
},
{
"type": "BLANK"
}
]
} }
] ]
}, },
@ -138,6 +185,48 @@
} }
] ]
}, },
"_connection_block": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "{"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_connection_block_definition"
}
},
{
"type": "STRING",
"value": "}"
}
]
},
"_connection_block_definition": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_eol"
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_connection_attribute"
},
{
"type": "SYMBOL",
"name": "_end"
}
]
}
]
},
"container": { "container": {
"type": "PREC", "type": "PREC",
"value": 2, "value": 2,
@ -178,9 +267,6 @@
} }
] ]
}, },
{
"type": "SEQ",
"members": [
{ {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
@ -241,8 +327,6 @@
} }
] ]
} }
]
}
}, },
"_container_block": { "_container_block": {
"type": "SEQ", "type": "SEQ",
@ -763,7 +847,161 @@
"type": "STRING", "type": "STRING",
"value": "near" "value": "near"
}, },
"_connection_attr_key": { "_connection_attribute": {
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_connection_arrowhead_attribute"
},
"named": true,
"value": "attribute"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_style_attribute"
},
"named": true,
"value": "attribute"
}
]
},
"_connection_arrowhead_attribute": {
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_connection_arrowhead_attr_key"
},
"named": true,
"value": "attr_key"
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "dot"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_style_attribute"
},
"named": true,
"value": "attribute"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_colon"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "label"
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_container_block"
},
"named": true,
"value": "block"
}
]
},
{
"type": "BLANK"
}
]
}
]
}
]
}
]
},
"_connection_arrowhead_block": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "{"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_eol"
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_shape_attribute"
},
{
"type": "SYMBOL",
"name": "_end"
}
]
}
]
}
},
{
"type": "STRING",
"value": "}"
}
]
},
"_connection_arrowhead_attr_key": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {

View file

@ -56,6 +56,10 @@
{ {
"type": "dot", "type": "dot",
"named": true "named": true
},
{
"type": "label",
"named": true
} }
] ]
} }
@ -99,6 +103,10 @@
"type": "arrow", "type": "arrow",
"named": true "named": true
}, },
{
"type": "block",
"named": true
},
{ {
"type": "container_key", "type": "container_key",
"named": true "named": true
@ -262,6 +270,10 @@
"named": true, "named": true,
"fields": {} "fields": {}
}, },
{
"type": "\u0000",
"named": false
},
{ {
"type": "\"", "type": "\"",
"named": false "named": false

Binary file not shown.

View file

@ -226,3 +226,169 @@ foo: {
) )
) )
================================================================================
Block style attributes inside a connection
================================================================================
foo -> bar: {
style: {
opacity: 5
fill: red
stroke: red
stroke-width: 5
stroke-dash: 4
border-radius: 1
font-color: red
shadow: true
multiple: true
animated: true
link: https://to
}
}
--------------------------------------------------------------------------------
(source_file
(connection
(shape_key)
(arrow)
(shape_key)
(block
(attribute
(attr_key)
(block
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
)
)
)
)
)
================================================================================
Labels for connection arrowheads
================================================================================
foo -> bar: {
source-arrowhead: 0
target-arrowhead: 1
}
--------------------------------------------------------------------------------
(source_file
(connection
(shape_key)
(arrow)
(shape_key)
(block
(attribute
(attr_key)
(label)
)
(attribute
(attr_key)
(label)
)
)
)
)
================================================================================
Block style attributes inside a connection arrowhead
================================================================================
foo -> bar: {
target-arrowhead: {
style: {
opacity: 5
fill: red
stroke: red
stroke-width: 5
stroke-dash: 4
border-radius: 1
font-color: red
shadow: true
multiple: true
animated: true
link: https://to
}
}
}
--------------------------------------------------------------------------------
(source_file
(connection
(shape_key)
(arrow)
(shape_key)
(block
(attribute
(attr_key)
(block
(attribute
(attr_key)
(block
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
)
)
)
)
)
)
)
================================================================================
Container attributes inside a connection arrowhead
================================================================================
foo -> bar: {
target-arrowhead: {
shape: oval
label: Baz
constraint: primary-key
icon: pathto
width: 100
height: 200
}
}
--------------------------------------------------------------------------------
(source_file
(connection
(shape_key)
(arrow)
(shape_key)
(block
(attribute
(attr_key)
(block
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
(attribute (attr_key) (attr_value))
)
)
)
)
)

Binary file not shown.