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

View File

@ -240,67 +240,63 @@
} }
}, },
"_container_block": { "_container_block": {
"type": "PREC", "type": "SEQ",
"value": 2, "members": [
"content": { {
"type": "SEQ", "type": "STRING",
"members": [ "value": "{"
{ },
"type": "STRING", {
"value": "{" "type": "REPEAT",
}, "content": {
{ "type": "SYMBOL",
"type": "REPEAT", "name": "_container_block_definition"
"content": {
"type": "SYMBOL",
"name": "_container_block_definition"
}
},
{
"type": "STRING",
"value": "}"
} }
] },
} {
"type": "STRING",
"value": "}"
}
]
}, },
"_container_block_definition": { "_container_block_definition": {
"type": "PREC", "type": "CHOICE",
"value": 4, "members": [
"content": { {
"type": "CHOICE", "type": "SYMBOL",
"members": [ "name": "_eol"
{ },
"type": "SYMBOL", {
"name": "_eol" "type": "SEQ",
}, "members": [
{ {
"type": "SEQ", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "CHOICE", "type": "SYMBOL",
"members": [ "name": "shape"
{ },
"type": "SYMBOL", {
"name": "shape" "type": "SYMBOL",
}, "name": "container"
{ },
"type": "SYMBOL", {
"name": "container" "type": "SYMBOL",
}, "name": "connection"
{ },
"type": "SYMBOL", {
"name": "connection" "type": "SYMBOL",
} "name": "_shape_attribute"
] }
}, ]
{ },
"type": "SYMBOL", {
"name": "_end" "type": "SYMBOL",
} "name": "_end"
] }
} ]
] }
} ]
}, },
"shape": { "shape": {
"type": "PREC", "type": "PREC",
@ -367,28 +363,6 @@
"type": "BLANK" "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": { "_root_attribute": {
"type": "SEQ", "type": "SEQ",
"members": [ "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": { "_shape_attr_key": {
"type": "PREC", "type": "PREC",
"value": 0, "value": 0,
@ -982,17 +964,8 @@
"type": "PREC", "type": "PREC",
"value": -1, "value": -1,
"content": { "content": {
"type": "CHOICE", "type": "STRING",
"members": [ "value": "\n"
{
"type": "STRING",
"value": "\n"
},
{
"type": "STRING",
"value": "\u0000"
}
]
} }
} }
}, },
@ -1029,10 +1002,6 @@
[ [
"_connection_path", "_connection_path",
"container" "container"
],
[
"_container_block_definition",
"_shape_block_definition"
] ]
], ],
"precedences": [], "precedences": [],

View File

@ -200,10 +200,6 @@
"type": "attribute", "type": "attribute",
"named": true "named": true
}, },
{
"type": "block",
"named": true
},
{ {
"type": "dot", "type": "dot",
"named": true "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 (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 Use quoted string as shape key and label
================================================================================ ================================================================================

View File

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

Binary file not shown.