grammar: add classes

Closes #12
This commit is contained in:
Dmitriy Pleshevskiy 2023-06-16 00:43:30 +03:00
parent 4ecaafdbe0
commit 8d8fd1bdf5
Signed by: pleshevskiy
GPG key ID: 79C4487B44403985
12 changed files with 1159 additions and 108 deletions

34
examples/classes.d2 Normal file
View file

@ -0,0 +1,34 @@
direction: right
classes: {
load balancer {
label: load\nbalancer
width: 100
height: 200
style: {
stroke-width: 0
fill: "#44C7B1"
shadow: true
border-radius: 5
}
}
unhealthy: {
style: {
fill: "#FE7070"
stroke: "#F69E03"
}
}
}
web traffic -> web lb
web lb.class: load balancer
web lb -> api1
web lb -> api2
web lb -> api3
api2.class: unhealthy
api1 -> cache lb
api3 -> cache lb
cache lb.class: load balancer

View file

@ -15,13 +15,28 @@
"type": "github" "type": "github"
} }
}, },
"flake-utils_2": {
"locked": {
"lastModified": 1678901627,
"narHash": "sha256-U02riOqrKKzwjsxc/400XnElV+UtPUQWpANPlyazjH0=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "93a2b84fc4b70d9e089d029deacc3583435c2ed6",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1669927173, "lastModified": 1686737040,
"narHash": "sha256-Z7rSKzC5OuWv5Q7RRNQPZb0jVJRJk0BJB6/fGZzaAIU=", "narHash": "sha256-R+JicNaI9mcxodtHkci894txjt4IMsfOnlAarA/r0xQ=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "9063accddd2e68dcc71032459a58399e977374c9", "rev": "6d1d80a232a355a65dc4d3bfea1f108e8dac1340",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -31,10 +46,114 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs_2": {
"locked": {
"lastModified": 1680005833,
"narHash": "sha256-BTMEjs+7hpmaP3n4hFVddrObMssANidP4EHgSpB0Lk0=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "bd4e35e14a0130268c8f7b253a15e09d76ec95b7",
"type": "github"
},
"original": {
"owner": "NixOS",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_volar": {
"locked": {
"lastModified": 1682598396,
"narHash": "sha256-vheqVF2Cfa2+gpqeymDukd/7ecNp+eamV5Ll0S9ElQ8=",
"owner": "ehllie",
"repo": "nixpkgs",
"rev": "fc9529215f7ebd9ff5a5c498c60f781f0beeaedd",
"type": "github"
},
"original": {
"owner": "ehllie",
"ref": "volar",
"repo": "nixpkgs",
"type": "github"
}
},
"poetry2nix": {
"inputs": {
"flake-utils": [
"tools",
"flake-utils"
],
"nixpkgs": [
"tools",
"nixpkgs"
]
},
"locked": {
"lastModified": 1679994832,
"narHash": "sha256-LSsvtnkambdSWeNYT8wWTjSFVFyyIYxrI77QDfzUCHI=",
"owner": "nix-community",
"repo": "poetry2nix",
"rev": "2a72eea5fbccc262855c87e3032837f8465db385",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "poetry2nix",
"type": "github"
}
},
"root": { "root": {
"inputs": { "inputs": {
"flake-utils": "flake-utils", "flake-utils": "flake-utils",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs",
"tools": "tools"
}
},
"tools": {
"inputs": {
"flake-utils": "flake-utils_2",
"nixpkgs": "nixpkgs_2",
"nixpkgs_volar": "nixpkgs_volar",
"poetry2nix": "poetry2nix",
"wd2": "wd2"
},
"locked": {
"lastModified": 1686758138,
"narHash": "sha256-aisJq5OU8qcvt82B6eSm8kOEukPAn7R5Qz9nIx1e7UQ=",
"ref": "refs/heads/main",
"rev": "32e27cb105f1ed5c7ee89032be6fb1a087eaa977",
"revCount": 44,
"type": "git",
"url": "https://git.pleshevski.ru/mynix/tools"
},
"original": {
"type": "git",
"url": "https://git.pleshevski.ru/mynix/tools"
}
},
"wd2": {
"inputs": {
"flake-utils": [
"tools",
"flake-utils"
],
"nixpkgs": [
"tools",
"nixpkgs"
]
},
"locked": {
"lastModified": 1680536082,
"narHash": "sha256-vGZxdADceCFjJAEuNYkpEvAPT8SD4Wd0cGSlhHTBDZk=",
"ref": "refs/heads/main",
"rev": "c4f9e3ea2679800dc04dc02957a8b460b2fc36cc",
"revCount": 22,
"type": "git",
"url": "https://git.pleshevski.ru/pleshevskiy/wd2"
},
"original": {
"type": "git",
"url": "https://git.pleshevski.ru/pleshevskiy/wd2"
} }
} }
}, },

View file

@ -2,9 +2,10 @@
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils"; flake-utils.url = "github:numtide/flake-utils";
tools.url = "git+https://git.pleshevski.ru/mynix/tools";
}; };
outputs = { self, nixpkgs, flake-utils, ... }: outputs = { self, nixpkgs, flake-utils, tools, ... }:
flake-utils.lib.eachDefaultSystem (system: flake-utils.lib.eachDefaultSystem (system:
let let
pkgs = import nixpkgs { inherit system; }; pkgs = import nixpkgs { inherit system; };
@ -13,6 +14,7 @@
devShells.default = pkgs.mkShell { devShells.default = pkgs.mkShell {
packages = with pkgs; [ packages = with pkgs; [
jq jq
tools.packages.${system}.d2
nodejs-18_x nodejs-18_x
tree-sitter tree-sitter
nodePackages.eslint nodePackages.eslint

View file

@ -6,6 +6,7 @@ const PREC = {
CONTAINER: 2, CONTAINER: 2,
CONNECTION: 2, CONNECTION: 2,
SHAPE: 3, SHAPE: 3,
CLASSES: 4,
IDENTIFIER: 0, IDENTIFIER: 0,
ARROW: 0, ARROW: 0,
ATTRIBUTE: 0, ATTRIBUTE: 0,
@ -33,6 +34,9 @@ module.exports = grammar({
[$._container_block], [$._container_block],
[$._connection_block], [$._connection_block],
[$._style_attribute_block], [$._style_attribute_block],
[$._classes_block],
[$._classes_item_block],
[$.class_list],
], ],
rules: { rules: {
@ -44,6 +48,7 @@ module.exports = grammar({
seq( seq(
choice( choice(
alias($._root_attribute, $.attribute), alias($._root_attribute, $.attribute),
$.classes,
$.shape, $.shape,
$.container, $.container,
$.connection $.connection
@ -82,6 +87,57 @@ module.exports = grammar({
"}" "}"
), ),
// classes
classes: ($) =>
prec(
PREC.CLASSES,
seq(
$.keyword_classes,
choice(
optional(seq($.dot, $._classes_item)),
seq(
optional(seq($._colon, optional($.label))),
optional(alias($._classes_block, $.block))
)
)
)
),
_classes_block: ($) =>
seq(
"{",
repeat(choice($._eol, seq($._classes_item, $._end))),
optional(seq($._classes_item, optional($._end))),
"}"
),
_classes_item: ($) =>
seq(
$._class_name,
choice(
optional(seq($.dot, $._shape_attribute)),
seq(
optional(seq($._colon, optional($.label))),
optional(alias($._classes_item_block, $.class_block))
)
)
),
_classes_item_block: ($) =>
seq(
"{",
repeat(choice($._eol, seq($._classes_item_attribute, $._end))),
optional(seq($._classes_item_attribute, optional($._end))),
"}"
),
_classes_item_attribute: ($) =>
choice(
alias($._base_shape_attribute, $.attribute),
alias($._style_attribute, $.attribute)
),
// containers // containers
container: ($) => container: ($) =>
@ -93,7 +149,7 @@ module.exports = grammar({
seq($.dot, choice($.shape, $.container)), seq($.dot, choice($.shape, $.container)),
seq( seq(
optional(seq($._colon, optional($.label))), optional(seq($._colon, optional($.label))),
optional(seq(alias($._container_block, $.block))) optional(alias($._container_block, $.block))
) )
) )
) )
@ -119,8 +175,8 @@ module.exports = grammar({
$.shape_key, $.shape_key,
optional( optional(
choice( choice(
seq($.dot, alias($._style_attribute, $.attribute)), seq($.dot, $._shape_attribute),
seq(optional(seq($._colon, choice($.label, $.text_block)))) seq($._colon, choice($.label, $.text_block))
) )
) )
) )
@ -168,7 +224,7 @@ module.exports = grammar({
"label", "label",
"constraint", "constraint",
"icon", "icon",
"style", $.keyword_style,
$._common_style_attr_key, $._common_style_attr_key,
$._text_attr_key $._text_attr_key
), ),
@ -177,11 +233,24 @@ module.exports = grammar({
), ),
_shape_attribute: ($) => _shape_attribute: ($) =>
choice( alias(
alias($._base_shape_attribute, $.attribute), choice($._class_attribute, $._base_shape_attribute, $._style_attribute),
alias($._style_attribute, $.attribute) $.attribute
), ),
_class_attribute: ($) =>
seq($.keyword_class, $._colon, choice($.class_list, $._class_name)),
class_list: ($) =>
seq(
"[",
repeat(choice($._eol, seq($._class_name, $._end))),
optional(seq($._class_name, optional($._end))),
"]"
),
_class_name: ($) => alias($.shape_key, $.class_name),
_base_shape_attribute: ($) => _base_shape_attribute: ($) =>
seq(alias($._shape_attr_key, $.attr_key), $._colon, $.attr_value), seq(alias($._shape_attr_key, $.attr_key), $._colon, $.attr_value),
@ -208,7 +277,7 @@ module.exports = grammar({
prec( prec(
PREC.ATTRIBUTE, PREC.ATTRIBUTE,
seq( seq(
alias("style", $.attr_key), $.keyword_style,
choice( choice(
seq($.dot, alias($._inner_style_attribute, $.attribute)), seq($.dot, alias($._inner_style_attribute, $.attribute)),
seq($._colon, alias($._style_attribute_block, $.block)) seq($._colon, alias($._style_attribute_block, $.block))
@ -245,6 +314,7 @@ module.exports = grammar({
"grid-columns", "grid-columns",
"grid-rows" "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: ($) =>
@ -295,6 +365,10 @@ module.exports = grammar({
_connection_arrowhead_attr_key: ($) => _connection_arrowhead_attr_key: ($) =>
choice("source-arrowhead", "target-arrowhead"), choice("source-arrowhead", "target-arrowhead"),
keyword_classes: (_) => "classes",
keyword_class: (_) => "class",
keyword_style: (_) => "style",
// //
label: ($) => choice($.string, $._unquoted_string), label: ($) => choice($.string, $._unquoted_string),

View file

@ -1,9 +1,15 @@
;------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------
(container_key) @constant (container_key) @string.special
(shape_key) @variable (shape_key) @variable
(attr_key) @property (attr_key) @property
(reserved) @error (reserved) @error
[
(keyword_style)
(keyword_classes)
(keyword_class)
] @keyword
(class_name) @constant
; Literals ; Literals
;------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------
@ -37,6 +43,8 @@
] @punctuation.delimiter ] @punctuation.delimiter
[ [
"["
"]"
"{" "{"
"}" "}"
"|" "|"

View file

@ -30,6 +30,10 @@
"named": true, "named": true,
"value": "attribute" "value": "attribute"
}, },
{
"type": "SYMBOL",
"name": "classes"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "shape" "name": "shape"
@ -251,6 +255,339 @@
} }
] ]
}, },
"classes": {
"type": "PREC",
"value": 4,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "keyword_classes"
},
{
"type": "CHOICE",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "dot"
},
{
"type": "SYMBOL",
"name": "_classes_item"
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_colon"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "label"
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_classes_block"
},
"named": true,
"value": "block"
},
{
"type": "BLANK"
}
]
}
]
}
]
}
]
}
},
"_classes_block": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "{"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_eol"
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_classes_item"
},
{
"type": "SYMBOL",
"name": "_end"
}
]
}
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_classes_item"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_end"
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "}"
}
]
},
"_classes_item": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_class_name"
},
{
"type": "CHOICE",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "dot"
},
{
"type": "SYMBOL",
"name": "_shape_attribute"
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_colon"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "label"
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_classes_item_block"
},
"named": true,
"value": "class_block"
},
{
"type": "BLANK"
}
]
}
]
}
]
}
]
},
"_classes_item_block": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "{"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_eol"
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_classes_item_attribute"
},
{
"type": "SYMBOL",
"name": "_end"
}
]
}
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_classes_item_attribute"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_end"
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "}"
}
]
},
"_classes_item_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"
}
]
},
"container": { "container": {
"type": "PREC", "type": "PREC",
"value": 2, "value": 2,
@ -325,9 +662,6 @@
}, },
{ {
"type": "CHOICE", "type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [ "members": [
{ {
"type": "ALIAS", "type": "ALIAS",
@ -337,8 +671,6 @@
}, },
"named": true, "named": true,
"value": "block" "value": "block"
}
]
}, },
{ {
"type": "BLANK" "type": "BLANK"
@ -464,22 +796,11 @@
"name": "dot" "name": "dot"
}, },
{ {
"type": "ALIAS",
"content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_style_attribute" "name": "_shape_attribute"
},
"named": true,
"value": "attribute"
} }
] ]
}, },
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{ {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
@ -501,13 +822,6 @@
] ]
} }
] ]
},
{
"type": "BLANK"
}
]
}
]
} }
] ]
}, },
@ -704,8 +1018,8 @@
"value": "icon" "value": "icon"
}, },
{ {
"type": "STRING", "type": "SYMBOL",
"value": "style" "name": "keyword_style"
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
@ -723,27 +1037,128 @@
] ]
}, },
"_shape_attribute": { "_shape_attribute": {
"type": "ALIAS",
"content": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "ALIAS", "type": "SYMBOL",
"content": { "name": "_class_attribute"
},
{
"type": "SYMBOL", "type": "SYMBOL",
"name": "_base_shape_attribute" "name": "_base_shape_attribute"
}, },
{
"type": "SYMBOL",
"name": "_style_attribute"
}
]
},
"named": true, "named": true,
"value": "attribute" "value": "attribute"
}, },
"_class_attribute": {
"type": "SEQ",
"members": [
{ {
"type": "SYMBOL",
"name": "keyword_class"
},
{
"type": "SYMBOL",
"name": "_colon"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "class_list"
},
{
"type": "SYMBOL",
"name": "_class_name"
}
]
}
]
},
"class_list": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "["
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_eol"
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_class_name"
},
{
"type": "SYMBOL",
"name": "_end"
}
]
}
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_class_name"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_end"
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "]"
}
]
},
"_class_name": {
"type": "ALIAS", "type": "ALIAS",
"content": { "content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_style_attribute" "name": "shape_key"
}, },
"named": true, "named": true,
"value": "attribute" "value": "class_name"
}
]
}, },
"_base_shape_attribute": { "_base_shape_attribute": {
"type": "SEQ", "type": "SEQ",
@ -823,13 +1238,8 @@
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
"type": "ALIAS", "type": "SYMBOL",
"content": { "name": "keyword_style"
"type": "STRING",
"value": "style"
},
"named": true,
"value": "attr_key"
}, },
{ {
"type": "CHOICE", "type": "CHOICE",
@ -1264,6 +1674,18 @@
} }
] ]
}, },
"keyword_classes": {
"type": "STRING",
"value": "classes"
},
"keyword_class": {
"type": "STRING",
"value": "class"
},
"keyword_style": {
"type": "STRING",
"value": "style"
},
"label": { "label": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
@ -1591,6 +2013,15 @@
], ],
[ [
"_style_attribute_block" "_style_attribute_block"
],
[
"_classes_block"
],
[
"_classes_item_block"
],
[
"class_list"
] ]
], ],
"precedences": [], "precedences": [],

View file

@ -69,10 +69,26 @@
"type": "block", "type": "block",
"named": true "named": true
}, },
{
"type": "class_list",
"named": true
},
{
"type": "class_name",
"named": true
},
{ {
"type": "dot", "type": "dot",
"named": true "named": true
}, },
{
"type": "keyword_class",
"named": true
},
{
"type": "keyword_style",
"named": true
},
{ {
"type": "label", "type": "label",
"named": true "named": true
@ -92,6 +108,14 @@
"type": "attribute", "type": "attribute",
"named": true "named": true
}, },
{
"type": "class_block",
"named": true
},
{
"type": "class_name",
"named": true
},
{ {
"type": "connection", "type": "connection",
"named": true "named": true
@ -100,6 +124,14 @@
"type": "container", "type": "container",
"named": true "named": true
}, },
{
"type": "dot",
"named": true
},
{
"type": "label",
"named": true
},
{ {
"type": "shape", "type": "shape",
"named": true "named": true
@ -112,6 +144,94 @@
"named": true, "named": true,
"fields": {} "fields": {}
}, },
{
"type": "class_block",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "attribute",
"named": true
}
]
}
},
{
"type": "class_list",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "class_name",
"named": true
}
]
}
},
{
"type": "class_name",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "escape_sequence",
"named": true
},
{
"type": "string",
"named": true
}
]
}
},
{
"type": "classes",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "attribute",
"named": true
},
{
"type": "block",
"named": true
},
{
"type": "class_block",
"named": true
},
{
"type": "class_name",
"named": true
},
{
"type": "dot",
"named": true
},
{
"type": "keyword_classes",
"named": true
},
{
"type": "label",
"named": true
}
]
}
},
{ {
"type": "connection", "type": "connection",
"named": true, "named": true,
@ -287,6 +407,10 @@
"type": "attribute", "type": "attribute",
"named": true "named": true
}, },
{
"type": "classes",
"named": true
},
{ {
"type": "connection", "type": "connection",
"named": true "named": true
@ -364,6 +488,14 @@
"type": ";", "type": ";",
"named": false "named": false
}, },
{
"type": "[",
"named": false
},
{
"type": "]",
"named": false
},
{ {
"type": "animated", "type": "animated",
"named": false "named": false
@ -460,6 +592,18 @@
"type": "italic", "type": "italic",
"named": false "named": false
}, },
{
"type": "keyword_class",
"named": true
},
{
"type": "keyword_classes",
"named": true
},
{
"type": "keyword_style",
"named": true
},
{ {
"type": "label", "type": "label",
"named": false "named": false

Binary file not shown.

View file

@ -62,18 +62,18 @@ foo.style.text-transform: uppercase
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(source_file (source_file
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value (float))))) (shape (shape_key) (dot) (attribute (keyword_style) (dot) (attribute (attr_key) (attr_value (float)))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value)))) (shape (shape_key) (dot) (attribute (keyword_style) (dot) (attribute (attr_key) (attr_value))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value)))) (shape (shape_key) (dot) (attribute (keyword_style) (dot) (attribute (attr_key) (attr_value))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value (integer))))) (shape (shape_key) (dot) (attribute (keyword_style) (dot) (attribute (attr_key) (attr_value (integer)))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value (integer))))) (shape (shape_key) (dot) (attribute (keyword_style) (dot) (attribute (attr_key) (attr_value (integer)))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value (integer))))) (shape (shape_key) (dot) (attribute (keyword_style) (dot) (attribute (attr_key) (attr_value (integer)))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value)))) (shape (shape_key) (dot) (attribute (keyword_style) (dot) (attribute (attr_key) (attr_value))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value (boolean))))) (shape (shape_key) (dot) (attribute (keyword_style) (dot) (attribute (attr_key) (attr_value (boolean)))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value (boolean))))) (shape (shape_key) (dot) (attribute (keyword_style) (dot) (attribute (attr_key) (attr_value (boolean)))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value (boolean))))) (shape (shape_key) (dot) (attribute (keyword_style) (dot) (attribute (attr_key) (attr_value (boolean)))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value)))) (shape (shape_key) (dot) (attribute (keyword_style) (dot) (attribute (attr_key) (attr_value))))
(shape (shape_key) (dot) (attribute (attr_key) (dot) (attribute (attr_key) (attr_value)))) (shape (shape_key) (dot) (attribute (keyword_style) (dot) (attribute (attr_key) (attr_value))))
) )
================================================================================ ================================================================================
@ -100,7 +100,7 @@ foo.style: {
(shape (shape
(shape_key) (dot) (shape_key) (dot)
(attribute (attribute
(attr_key) (keyword_style)
(block (block
(attribute (attr_key) (attr_value (float))) (attribute (attr_key) (attr_value (float)))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value))
@ -174,17 +174,17 @@ foo: {
(container (container
(container_key) (container_key)
(block (block
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value (float)))) (attribute (keyword_style) (dot) (attribute (attr_key) (attr_value (float))))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value))) (attribute (keyword_style) (dot) (attribute (attr_key) (attr_value)))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value))) (attribute (keyword_style) (dot) (attribute (attr_key) (attr_value)))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value (integer)))) (attribute (keyword_style) (dot) (attribute (attr_key) (attr_value (integer))))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value (integer)))) (attribute (keyword_style) (dot) (attribute (attr_key) (attr_value (integer))))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value (integer)))) (attribute (keyword_style) (dot) (attribute (attr_key) (attr_value (integer))))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value))) (attribute (keyword_style) (dot) (attribute (attr_key) (attr_value)))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value (boolean)))) (attribute (keyword_style) (dot) (attribute (attr_key) (attr_value (boolean))))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value (boolean)))) (attribute (keyword_style) (dot) (attribute (attr_key) (attr_value (boolean))))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value (boolean)))) (attribute (keyword_style) (dot) (attribute (attr_key) (attr_value (boolean))))
(attribute (attr_key) (dot) (attribute (attr_key) (attr_value))) (attribute (keyword_style) (dot) (attribute (attr_key) (attr_value)))
) )
) )
) )
@ -215,7 +215,7 @@ foo: {
(container_key) (container_key)
(block (block
(attribute (attribute
(attr_key) (keyword_style)
(block (block
(attribute (attr_key) (attr_value (float))) (attribute (attr_key) (attr_value (float)))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value))
@ -262,7 +262,7 @@ foo -> bar: {
(shape_key) (shape_key)
(block (block
(attribute (attribute
(attr_key) (keyword_style)
(block (block
(attribute (attr_key) (attr_value (float))) (attribute (attr_key) (attr_value (float)))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value))
@ -367,7 +367,7 @@ foo -> bar: {
(attr_key) (attr_key)
(block (block
(attribute (attribute
(attr_key) (keyword_style)
(block (block
(attribute (attr_key) (attr_value (float))) (attribute (attr_key) (attr_value (float)))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value))
@ -436,7 +436,7 @@ foo.style: {opacity: 0.5; fill: red}
(shape (shape
(shape_key) (dot) (shape_key) (dot)
(attribute (attribute
(attr_key) (keyword_style)
(block (block
(attribute (attr_key) (attr_value (float))) (attribute (attr_key) (attr_value (float)))
(attribute (attr_key) (attr_value)) (attribute (attr_key) (attr_value))

198
test/corpus/classes.txt Normal file
View file

@ -0,0 +1,198 @@
================================================================================
Declare empty classes keyword in the root
================================================================================
classes
--------------------------------------------------------------------------------
(source_file
(classes (keyword_classes))
)
================================================================================
Declare classes block with item block
================================================================================
classes: {
foo: {
style: {
fill: "#44C7B1"
}
}
}
--------------------------------------------------------------------------------
(source_file
(classes
(keyword_classes)
(block
(class_name)
(class_block
(attribute
(keyword_style)
(block
(attribute
(attr_key)
(attr_value
(string (string_fragment))
)
)
)
)
)
)
)
)
================================================================================
Declare classes block with item inline
================================================================================
classes: {
foo.style: {
fill: "#44C7B1"
}
}
--------------------------------------------------------------------------------
(source_file
(classes
(keyword_classes)
(block
(class_name)
(dot)
(attribute
(keyword_style)
(block
(attribute
(attr_key)
(attr_value
(string (string_fragment))
)
)
)
)
)
)
)
================================================================================
Declare classes inline with item inline
================================================================================
classes.foo.style: {
fill: "#44C7B1"
}
--------------------------------------------------------------------------------
(source_file
(classes
(keyword_classes)
(dot)
(class_name)
(dot)
(attribute
(keyword_style)
(block
(attribute
(attr_key)
(attr_value
(string (string_fragment))
)
)
)
)
)
)
================================================================================
Declare classes inline with item block
================================================================================
classes.foo: {
style: {
fill: "#44C7B1"
}
}
--------------------------------------------------------------------------------
(source_file
(classes
(keyword_classes)
(dot)
(class_name)
(class_block
(attribute
(keyword_style)
(block
(attribute
(attr_key)
(attr_value
(string (string_fragment))
)
)
)
)
)
)
)
================================================================================
Declare shape with a class
================================================================================
foo.class: biz
--------------------------------------------------------------------------------
(source_file
(shape
(shape_key)
(dot)
(attribute
(keyword_class)
(class_name)
)
)
)
================================================================================
Declare shape with many classes
================================================================================
foo.class: [biz; baz]
--------------------------------------------------------------------------------
(source_file
(shape
(shape_key)
(dot)
(attribute
(keyword_class)
(class_list
(class_name)
(class_name)
)
)
)
)
================================================================================
Declare a class in the container
================================================================================
foo: {
class: biz
}
--------------------------------------------------------------------------------
(source_file
(container
(container_key)
(block
(attribute
(keyword_class)
(class_name)
)
)
)
)

View file

@ -10,7 +10,7 @@ shape: oval
baaaz.style: { baaaz.style: {
# <- variable # <- variable
# ^ property # ^ keyword
fill: red fill: red
# <- property # <- property
# ^ string # ^ string
@ -22,12 +22,13 @@ foo: Label {
# ^ string # ^ string
style.fill: red; style.fill: red;
# <- property # <- keyword
# ^ property # ^ property
} }
foo: { foo: {
style: { style: {
# <- keyword
opacity: 0.5 opacity: 0.5
# ^ float # ^ float
fill: red fill: red
@ -54,6 +55,6 @@ foo: Label {
# ^ string # ^ string
style.fill: red style.fill: red
# <- property # <- keyword
# ^ property # ^ property
} }

40
test/highlight/classes.d2 Normal file
View file

@ -0,0 +1,40 @@
classes: {
# <- keyword
# ^ punctuation.delimiter
# ^ punctuation.bracket
load balancer {
label: load\nbalancer
width: 100
height: 200
style: {
stroke-width: 0
fill: "#44C7B1"
shadow: true
border-radius: 5
}
}
unhealthy: {
style: {
fill: "#FE7070"
stroke: "#F69E03"
}
}
}
web traffic -> web lb
web lb.class: load balancer
# <- variable
# ^ punctuation.delimiter
# ^ keyword
# ^ punctuation.delimiter
web lb -> api1
web lb -> api2
web lb -> api3
api2.class: unhealthy
api1 -> cache lb
api3 -> cache lb
cache lb.class: load balancer