add style attributes

This commit is contained in:
Dmitriy Pleshevskiy 2022-12-09 11:24:48 +03:00
parent f279551465
commit 781eb62b37
Signed by: pleshevskiy
GPG Key ID: 1B59187B161C0215
5 changed files with 338 additions and 61 deletions

View File

@ -111,9 +111,12 @@ module.exports = grammar({
seq( seq(
$.shape_key, $.shape_key,
optional( optional(
seq( choice(
optional(seq($._colon, optional($.label))), seq($._dot, alias($._style_attribute, $.attribute)),
optional(seq(alias($._new_shape_block, $.block))) seq(
optional(seq($._colon, optional($.label))),
optional(seq(alias($._new_shape_block, $.block)))
)
) )
) )
) )
@ -132,10 +135,7 @@ module.exports = grammar({
// attributes // attributes
_new_root_attribute: ($) => _new_root_attribute: ($) =>
prec( seq(alias($._root_attr_key, $.attr_key), $._colon, $.attr_value),
PREC.ATTRIBUTE,
seq(alias($._root_attr_key, $.attr_key), $._colon, $.attr_value)
),
_root_attr_key: ($) => _root_attr_key: ($) =>
choice( choice(
@ -147,6 +147,7 @@ module.exports = grammar({
"label", "label",
"constraint", "constraint",
"icon", "icon",
"style",
$._common_style_attr_key, $._common_style_attr_key,
$._text_attr_key $._text_attr_key
), ),
@ -169,6 +170,36 @@ module.exports = grammar({
) )
), ),
_style_attribute: ($) =>
prec(
PREC.ATTRIBUTE,
seq(
alias("style", $.attr_key),
choice(
seq($._dot, alias($._inner_style_attribute, $.attribute)),
seq($._colon, alias($._style_attribute_block, $.block))
)
)
),
_style_attribute_block: ($) =>
seq(
"{",
repeat(
choice(
$._eol,
seq(alias($._inner_style_attribute, $.attribute), $._end)
)
),
"}"
),
_inner_style_attribute: ($) =>
prec(
PREC.ATTRIBUTE,
seq(alias($._style_attr_key, $.attr_key), $._colon, $.attr_value)
),
_style_attr_key: ($) => choice($._common_style_attr_key, "3d"), _style_attr_key: ($) => choice($._common_style_attr_key, "3d"),
_common_style_attr_key: ($) => _common_style_attr_key: ($) =>

View File

@ -316,56 +316,79 @@
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "SEQ", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "CHOICE", "type": "SEQ",
"members": [ "members": [
{ {
"type": "SEQ", "type": "SYMBOL",
"members": [ "name": "_dot"
{
"type": "SYMBOL",
"name": "_colon"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "label"
},
{
"type": "BLANK"
}
]
}
]
}, },
{ {
"type": "BLANK" "type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_style_attribute"
},
"named": true,
"value": "attribute"
} }
] ]
}, },
{ {
"type": "CHOICE", "type": "SEQ",
"members": [ "members": [
{ {
"type": "SEQ", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "ALIAS", "type": "SEQ",
"content": { "members": [
"type": "SYMBOL", {
"name": "_new_shape_block" "type": "SYMBOL",
}, "name": "_colon"
"named": true, },
"value": "block" {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "label"
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "BLANK"
} }
] ]
}, },
{ {
"type": "BLANK" "type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_new_shape_block"
},
"named": true,
"value": "block"
}
]
},
{
"type": "BLANK"
}
]
} }
] ]
} }
@ -458,30 +481,26 @@
} }
}, },
"_new_root_attribute": { "_new_root_attribute": {
"type": "PREC", "type": "SEQ",
"value": 0, "members": [
"content": { {
"type": "SEQ", "type": "ALIAS",
"members": [ "content": {
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_root_attr_key"
},
"named": true,
"value": "attr_key"
},
{
"type": "SYMBOL", "type": "SYMBOL",
"name": "_colon" "name": "_root_attr_key"
}, },
{ "named": true,
"type": "SYMBOL", "value": "attr_key"
"name": "attr_value" },
} {
] "type": "SYMBOL",
} "name": "_colon"
},
{
"type": "SYMBOL",
"name": "attr_value"
}
]
}, },
"_root_attr_key": { "_root_attr_key": {
"type": "CHOICE", "type": "CHOICE",
@ -511,6 +530,10 @@
"type": "STRING", "type": "STRING",
"value": "icon" "value": "icon"
}, },
{
"type": "STRING",
"value": "style"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_common_style_attr_key" "name": "_common_style_attr_key"
@ -559,6 +582,134 @@
] ]
} }
}, },
"_style_attribute": {
"type": "PREC",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "style"
},
"named": true,
"value": "attr_key"
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_dot"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_inner_style_attribute"
},
"named": true,
"value": "attribute"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_colon"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_style_attribute_block"
},
"named": true,
"value": "block"
}
]
}
]
}
]
}
},
"_style_attribute_block": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "{"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_eol"
},
{
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_inner_style_attribute"
},
"named": true,
"value": "attribute"
},
{
"type": "SYMBOL",
"name": "_end"
}
]
}
]
}
},
{
"type": "STRING",
"value": "}"
}
]
},
"_inner_style_attribute": {
"type": "PREC",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_style_attr_key"
},
"named": true,
"value": "attr_key"
},
{
"type": "SYMBOL",
"name": "_colon"
},
{
"type": "SYMBOL",
"name": "attr_value"
}
]
}
},
"_style_attr_key": { "_style_attr_key": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [

View File

@ -44,6 +44,18 @@
{ {
"type": "attr_value", "type": "attr_value",
"named": true "named": true
},
{
"type": "attribute",
"named": true
},
{
"type": "block",
"named": true
},
{
"type": "dot",
"named": true
} }
] ]
} }
@ -56,6 +68,10 @@
"multiple": true, "multiple": true,
"required": false, "required": false,
"types": [ "types": [
{
"type": "attribute",
"named": true
},
{ {
"type": "connection", "type": "connection",
"named": true "named": true
@ -180,10 +196,18 @@
"multiple": true, "multiple": true,
"required": true, "required": true,
"types": [ "types": [
{
"type": "attribute",
"named": true
},
{ {
"type": "block", "type": "block",
"named": true "named": true
}, },
{
"type": "dot",
"named": true
},
{ {
"type": "label", "type": "label",
"named": true "named": true

Binary file not shown.

View File

@ -43,3 +43,74 @@ near: abc
(attribute (attr_key (reserved)) (attr_value)) (attribute (attr_key (reserved)) (attr_value))
) )
================================================================================
Style attribute
================================================================================
foo.style.opacity: 5
foo.style.fill: red
foo.style.stroke: red
foo.style.stroke-width: 5
foo.style.stroke-dash: 4
foo.style.border-radius: 1
foo.style.font-color: red
foo.style.shadow: true
foo.style.multiple: true
foo.style.animated: true
foo.style.link: https://to
--------------------------------------------------------------------------------
(source_file
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value))))
)
================================================================================
Block style attributes
================================================================================
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
(shape
(shape_key) (dot)
(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))
)
)
)
)