grammar: add grid-row, grid-column, grid-gap

Closes #13
This commit is contained in:
Dmitriy Pleshevskiy 2023-06-14 09:07:37 +03:00
parent eb6910126f
commit c6b812fd8d
Signed by: pleshevskiy
GPG key ID: 79C4487B44403985
6 changed files with 119 additions and 2 deletions

View file

@ -160,6 +160,7 @@ module.exports = grammar({
_root_attr_key: ($) => _root_attr_key: ($) =>
choice( choice(
"direction", "direction",
$._grid_attr_key,
// reserved but doesn't affected for root // reserved but doesn't affected for root
alias( alias(
choice( choice(
@ -198,7 +199,8 @@ module.exports = grammar({
// image // image
"icon", "icon",
"width", "width",
"height" "height",
$._grid_attr_key
) )
), ),
@ -235,6 +237,7 @@ module.exports = grammar({
seq(alias($._style_attr_key, $.attr_key), $._colon, $.attr_value) seq(alias($._style_attr_key, $.attr_key), $._colon, $.attr_value)
), ),
_grid_attr_key: ($) => choice("grid-gap", "grid-columns", "grid-rows"),
_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

@ -678,6 +678,10 @@
"type": "STRING", "type": "STRING",
"value": "direction" "value": "direction"
}, },
{
"type": "SYMBOL",
"name": "_grid_attr_key"
},
{ {
"type": "ALIAS", "type": "ALIAS",
"content": { "content": {
@ -804,6 +808,10 @@
{ {
"type": "STRING", "type": "STRING",
"value": "height" "value": "height"
},
{
"type": "SYMBOL",
"name": "_grid_attr_key"
} }
] ]
} }
@ -970,6 +978,23 @@
] ]
} }
}, },
"_grid_attr_key": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "grid-gap"
},
{
"type": "STRING",
"value": "grid-columns"
},
{
"type": "STRING",
"value": "grid-rows"
}
]
},
"_style_attr_key": { "_style_attr_key": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [

View file

@ -428,6 +428,18 @@
"type": "font-size", "type": "font-size",
"named": false "named": false
}, },
{
"type": "grid-columns",
"named": false
},
{
"type": "grid-gap",
"named": false
},
{
"type": "grid-rows",
"named": false
},
{ {
"type": "height", "type": "height",
"named": false "named": false

Binary file not shown.

View file

@ -422,7 +422,7 @@ foo -> bar: {
) )
================================================================================ ================================================================================
Declire style attributes in single-line Declare style attributes in single-line
================================================================================ ================================================================================
foo.style: {opacity: 0.5; fill: red} foo.style: {opacity: 0.5; fill: red}
@ -441,3 +441,41 @@ foo.style: {opacity: 0.5; fill: red}
) )
) )
================================================================================
Declare grid attributes
================================================================================
grid-gap: 0
grid-columns: 1
header
body: "" {
grid-gap: 0
grid-columns: 2
content
sidebar
}
footer
--------------------------------------------------------------------------------
(source_file
(attribute (attr_key) (attr_value (integer)))
(attribute (attr_key) (attr_value (integer)))
(shape (shape_key))
(container
(container_key)
(label (string))
(block
(attribute (attr_key) (attr_value (integer)))
(attribute (attr_key) (attr_value (integer)))
(shape (shape_key))
(shape (shape_key))
)
)
(shape (shape_key))
)

39
test/highlight/grid.d2 Normal file
View file

@ -0,0 +1,39 @@
grid-gap: 0
# <- property
# ^ property
# ^ property
# ^ punctuation.delimiter
# ^ number
grid-columns: 1
# <- property
# ^ punctuation.delimiter
# ^ number
header
# <- variable
body: "" {
# <- constant
# ^ punctuation.delimiter
# ^ string
# ^ punctuation.bracket
grid-gap: 0
# <- property
# ^ property
# ^ property
# ^ punctuation.delimiter
# ^ number
grid-columns: 2
# <- property
# ^ punctuation.delimiter
# ^ number
content
# <- variable
sidebar
# <- variable
}
# <- punctuation.bracket
footer
# <- variable