Add structure for container and shapes #1

Merged
pleshevskiy merged 12 commits from rewrite-structure into main 2022-12-09 12:36:32 +03:00
5 changed files with 338 additions and 61 deletions
Showing only changes of commit 781eb62b37 - Show all commits

View file

@ -111,12 +111,15 @@ module.exports = grammar({
seq( seq(
$.shape_key, $.shape_key,
optional( optional(
choice(
seq($._dot, alias($._style_attribute, $.attribute)),
seq( seq(
optional(seq($._colon, optional($.label))), optional(seq($._colon, optional($.label))),
optional(seq(alias($._new_shape_block, $.block))) optional(seq(alias($._new_shape_block, $.block)))
) )
) )
) )
)
), ),
shape_key: ($) => choice($.string, seq($._identifier, optional($._dash))), shape_key: ($) => choice($.string, seq($._identifier, optional($._dash))),
@ -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

@ -315,6 +315,27 @@
{ {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_dot"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_style_attribute"
},
"named": true,
"value": "attribute"
}
]
},
{ {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
@ -370,6 +391,8 @@
] ]
} }
] ]
}
]
}, },
{ {
"type": "BLANK" "type": "BLANK"
@ -458,9 +481,6 @@
} }
}, },
"_new_root_attribute": { "_new_root_attribute": {
"type": "PREC",
"value": 0,
"content": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
@ -481,7 +501,6 @@
"name": "attr_value" "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))
)
)
)
)