add attributes for container

This commit is contained in:
Dmitriy Pleshevskiy 2022-12-09 12:34:42 +03:00
parent 7310e22538
commit e674629993
Signed by: pleshevskiy
GPG Key ID: 1B59187B161C0215
8 changed files with 1605 additions and 1551 deletions

View File

@ -5,8 +5,6 @@ const PREC = {
CONTAINER: 2,
CONNECTION: 2,
SHAPE: 3,
CONTAINER_BLOCK: 4,
SHAPE_BLOCK: 4,
IDENTIFIER: 0,
ARROW: 0,
ATTRIBUTE: 0,
@ -23,10 +21,7 @@ module.exports = grammar({
word: ($) => $._identifier,
conflicts: ($) => [
[$._connection_path, $.container],
[$._container_block_definition, $._shape_block_definition],
],
conflicts: ($) => [[$._connection_path, $.container]],
rules: {
source_file: ($) => repeat($._root_definition),
@ -82,15 +77,15 @@ module.exports = grammar({
),
_container_block: ($) =>
prec(
PREC.CONTAINER,
seq("{", repeat($._container_block_definition), "}")
),
seq("{", repeat($._container_block_definition), "}"),
_container_block_definition: ($) =>
prec(
PREC.CONTAINER_BLOCK,
choice($._eol, seq(choice($.shape, $.container, $.connection), $._end))
choice(
$._eol,
seq(
choice($.shape, $.container, $.connection, $._shape_attribute),
$._end
)
),
// shapes
@ -103,10 +98,7 @@ module.exports = grammar({
optional(
choice(
seq($.dot, alias($._style_attribute, $.attribute)),
seq(
optional(seq($._colon, optional($.label))),
optional(seq(alias($._shape_block, $.block)))
)
seq(optional(seq($._colon, optional($.label))))
)
)
)
@ -117,11 +109,6 @@ module.exports = grammar({
_identifier: ($) =>
token(prec(PREC.IDENTIFIER, /\-?([\w\d]+|([\w\d]+( +|\-)[\w\d]+)+)/)),
_shape_block: ($) =>
prec(PREC.SHAPE, seq("{", repeat($._shape_block_definition), "}")),
_shape_block_definition: ($) => prec(PREC.SHAPE_BLOCK, choice($._eol)),
// attributes
_root_attribute: ($) =>
@ -145,6 +132,15 @@ module.exports = grammar({
)
),
_shape_attribute: ($) =>
choice(
alias($._base_shape_attribute, $.attribute),
alias($._style_attribute, $.attribute)
),
_base_shape_attribute: ($) =>
seq(alias($._shape_attr_key, $.attr_key), $._colon, $.attr_value),
_shape_attr_key: ($) =>
prec(
PREC.ATTRIBUTE_KEY,

View File

@ -240,67 +240,63 @@
}
},
"_container_block": {
"type": "PREC",
"value": 2,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "{"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_container_block_definition"
}
},
{
"type": "STRING",
"value": "}"
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "{"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_container_block_definition"
}
]
}
},
{
"type": "STRING",
"value": "}"
}
]
},
"_container_block_definition": {
"type": "PREC",
"value": 4,
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_eol"
},
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "shape"
},
{
"type": "SYMBOL",
"name": "container"
},
{
"type": "SYMBOL",
"name": "connection"
}
]
},
{
"type": "SYMBOL",
"name": "_end"
}
]
}
]
}
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_eol"
},
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "shape"
},
{
"type": "SYMBOL",
"name": "container"
},
{
"type": "SYMBOL",
"name": "connection"
},
{
"type": "SYMBOL",
"name": "_shape_attribute"
}
]
},
{
"type": "SYMBOL",
"name": "_end"
}
]
}
]
},
"shape": {
"type": "PREC",
@ -367,28 +363,6 @@
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_shape_block"
},
"named": true,
"value": "block"
}
]
},
{
"type": "BLANK"
}
]
}
]
}
@ -443,43 +417,6 @@
}
}
},
"_shape_block": {
"type": "PREC",
"value": 3,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "{"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_shape_block_definition"
}
},
{
"type": "STRING",
"value": "}"
}
]
}
},
"_shape_block_definition": {
"type": "PREC",
"value": 4,
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_eol"
}
]
}
},
"_root_attribute": {
"type": "SEQ",
"members": [
@ -549,6 +486,51 @@
}
]
},
"_shape_attribute": {
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_base_shape_attribute"
},
"named": true,
"value": "attribute"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_style_attribute"
},
"named": true,
"value": "attribute"
}
]
},
"_base_shape_attribute": {
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_shape_attr_key"
},
"named": true,
"value": "attr_key"
},
{
"type": "SYMBOL",
"name": "_colon"
},
{
"type": "SYMBOL",
"name": "attr_value"
}
]
},
"_shape_attr_key": {
"type": "PREC",
"value": 0,
@ -982,17 +964,8 @@
"type": "PREC",
"value": -1,
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "\n"
},
{
"type": "STRING",
"value": "\u0000"
}
]
"type": "STRING",
"value": "\n"
}
}
},
@ -1029,10 +1002,6 @@
[
"_connection_path",
"container"
],
[
"_container_block_definition",
"_shape_block_definition"
]
],
"precedences": [],

View File

@ -200,10 +200,6 @@
"type": "attribute",
"named": true
},
{
"type": "block",
"named": true
},
{
"type": "dot",
"named": true

File diff suppressed because it is too large Load Diff

View File

@ -114,3 +114,115 @@ foo.style: {
)
)
)
================================================================================
Container attributes
================================================================================
foo: {
shape: oval
label: Baz
constraint: primary-key
icon: pathto
width: 100
height: 200
}
--------------------------------------------------------------------------------
(source_file
(container
(container_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))
)
)
)
================================================================================
Container style attributes
================================================================================
foo: {
style.opacity: 5
style.fill: red
style.stroke: red
style.stroke-width: 5
style.stroke-dash: 4
style.border-radius: 1
style.font-color: red
style.shadow: true
style.multiple: true
style.animated: true
style.link: https://to
}
--------------------------------------------------------------------------------
(source_file
(container
(container_key)
(block
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value)))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value)))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value)))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value)))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value)))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value)))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value)))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value)))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value)))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value)))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value)))
)
)
)
================================================================================
Block style attributes inside a container
================================================================================
foo: {
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
(container
(container_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))
)
)
)
)
)

View File

@ -78,32 +78,6 @@ bar : Foo Bar; baz
(shape (shape_key))
)
================================================================================
Shape block
================================================================================
foo: {}
bar {}
--------------------------------------------------------------------------------
(source_file
(shape (shape_key) (block))
(shape (shape_key) (block))
)
================================================================================
Labeled shape block
================================================================================
foo: Foo {}
--------------------------------------------------------------------------------
(source_file
(shape (shape_key) (label) (block))
)
================================================================================
Use quoted string as shape key and label
================================================================================

View File

@ -6,7 +6,7 @@ direction: right;
shape: oval
# <- error
# ^ error
# ^ string
baaaz.style: {
# <- variable

Binary file not shown.