add support of shape path

This commit is contained in:
Dmitriy Pleshevskiy 2022-12-07 23:14:25 +03:00
parent 867ed6662b
commit 2871ceb718
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
12 changed files with 277 additions and 230 deletions

View file

@ -1,2 +1,2 @@
a.shape: oval
'a'.'B'.shape: oval
b

View file

@ -8,9 +8,10 @@ module.exports = grammar({
word: ($) => $._word,
conflicts: ($) => [
[$.identifier],
[$.shape_key],
[$.arrow],
[$._identifier],
[$._shape_path],
[$._shape_key],
[$._shape_block],
[$._shape_block_definition],
[$._style_attr_block],
@ -19,25 +20,29 @@ module.exports = grammar({
],
rules: {
source_file: ($) => repeat($._definition),
source_file: ($) => repeat($._root_definition),
_definition: ($) =>
choice($._emptyline, $._root_attribute, $.connection, $.shape),
_root_definition: ($) =>
choice(
$._emptyline,
$._root_attribute,
$.connection,
$._shape_definition
),
connection: ($) =>
seq(
$._identifier,
repeat1(seq($._arrow, $._identifier)),
$._shape_path,
repeat1(seq($._arrow, $._shape_path)),
optional(
choice(seq($.dot, $._connection_attribute), seq($._colon, $.label))
),
$._end
),
shape: ($) =>
_shape_definition: ($) =>
seq(
$._identifier,
repeat(seq($.dot, $._identifier)),
$._shape_path,
optional(
choice(
seq($.dot, $._shape_attribute),
@ -50,6 +55,12 @@ module.exports = grammar({
$._end
),
_shape_path: ($) =>
choice(
$._shape_key,
seq($._shape_key, repeat1(seq($.dot, $._shape_key)))
),
label: ($) => choice($.string, $._unquoted_string),
attr_value: ($) => seq(spaces, choice($.string, $._unquoted_string)),
@ -80,7 +91,7 @@ module.exports = grammar({
),
_shape_block_definition: ($) =>
choice($.connection, $.shape, $._shape_attribute),
choice($.connection, $._shape_definition, $._shape_attribute),
_shape_attribute: ($) =>
choice(
@ -146,16 +157,19 @@ module.exports = grammar({
_connection_attr_key: ($) => choice("source-arrowhead", "target-arrowhead"),
_identifier: ($) => seq(spaces, $.identifier),
_shape_key: ($) => seq(spaces, $.shape_key),
identifier: ($) =>
shape_key: ($) =>
choice(
$.string,
seq(
optional($._dash),
choice(
$._word,
repeat1(seq($._word, choice(spaces, $._dash), $._word))
repeat1(seq($._word, choice(repeat1(" "), $._dash), $._word))
),
optional($._dash)
)
),
_colon: ($) => seq(spaces, ":"),

View file

@ -5,7 +5,7 @@
(invalid (_) @error)
;-------------------------------------------------------------------------------
(identifier) @variable
(shape_key) @variable
(attr_key) @keyword
; Literals
@ -26,7 +26,6 @@
(arrow) @operator
[
(dot)
":"
";"
] @punctuation.delimiter

View file

@ -6,10 +6,10 @@
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_definition"
"name": "_root_definition"
}
},
"_definition": {
"_root_definition": {
"type": "CHOICE",
"members": [
{
@ -26,7 +26,7 @@
},
{
"type": "SYMBOL",
"name": "shape"
"name": "_shape_definition"
}
]
},
@ -35,7 +35,7 @@
"members": [
{
"type": "SYMBOL",
"name": "_identifier"
"name": "_shape_path"
},
{
"type": "REPEAT1",
@ -48,7 +48,7 @@
},
{
"type": "SYMBOL",
"name": "_identifier"
"name": "_shape_path"
}
]
}
@ -98,28 +98,12 @@
}
]
},
"shape": {
"_shape_definition": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_identifier"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "dot"
},
{
"type": "SYMBOL",
"name": "_identifier"
}
]
}
"name": "_shape_path"
},
{
"type": "CHOICE",
@ -204,6 +188,40 @@
}
]
},
"_shape_path": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_shape_key"
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_shape_key"
},
{
"type": "REPEAT1",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "dot"
},
{
"type": "SYMBOL",
"name": "_shape_key"
}
]
}
}
]
}
]
},
"label": {
"type": "CHOICE",
"members": [
@ -428,7 +446,7 @@
},
{
"type": "SYMBOL",
"name": "shape"
"name": "_shape_definition"
},
{
"type": "SYMBOL",
@ -791,7 +809,7 @@
}
]
},
"_identifier": {
"_shape_key": {
"type": "SEQ",
"members": [
{
@ -812,11 +830,18 @@
},
{
"type": "SYMBOL",
"name": "identifier"
"name": "shape_key"
}
]
},
"identifier": {
"shape_key": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "string"
},
{
"type": "SEQ",
"members": [
{
@ -851,19 +876,10 @@
"type": "CHOICE",
"members": [
{
"type": "REPEAT",
"type": "REPEAT1",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": " "
},
{
"type": "STRING",
"value": "\t"
}
]
}
},
{
@ -894,6 +910,8 @@
]
}
]
}
]
},
"_colon": {
"type": "SEQ",
@ -1214,13 +1232,16 @@
],
"conflicts": [
[
"identifier"
"shape_key"
],
[
"arrow"
],
[
"_identifier"
"_shape_path"
],
[
"_shape_key"
],
[
"_shape_block"

View file

@ -53,7 +53,11 @@
"named": true
},
{
"type": "shape",
"type": "label",
"named": true
},
{
"type": "shape_key",
"named": true
}
]
@ -84,21 +88,16 @@
"named": true
},
{
"type": "identifier",
"type": "label",
"named": true
},
{
"type": "label",
"type": "shape_key",
"named": true
}
]
}
},
{
"type": "identifier",
"named": true,
"fields": {}
},
{
"type": "invalid",
"named": true,
@ -142,35 +141,15 @@
}
},
{
"type": "shape",
"type": "shape_key",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"multiple": false,
"required": false,
"types": [
{
"type": "attr_key",
"named": true
},
{
"type": "attr_value",
"named": true
},
{
"type": "block",
"named": true
},
{
"type": "dot",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "label",
"type": "string",
"named": true
}
]
@ -192,16 +171,28 @@
"type": "attr_value",
"named": true
},
{
"type": "block",
"named": true
},
{
"type": "connection",
"named": true
},
{
"type": "dot",
"named": true
},
{
"type": "invalid",
"named": true
},
{
"type": "shape",
"type": "label",
"named": true
},
{
"type": "shape_key",
"named": true
}
]

Binary file not shown.

View file

@ -23,12 +23,14 @@ foo: {
--------------------------------------------------------------------------------
(source_file
(shape (identifier) (block
(shape_key)
(block
(attr_key) (attr_value)
(shape (identifier) (dot) (identifier) (dot) (identifier) (block
(shape_key) (dot) (shape_key) (dot) (shape_key)
(block
(attr_key) (attr_value)
))
))
)
)
)
@ -41,8 +43,8 @@ foo.bar.baz.shape: oval
--------------------------------------------------------------------------------
(source_file
(shape (identifier) (dot) (attr_key) (attr_value))
(shape (identifier) (dot) (identifier) (dot) (identifier) (dot) (attr_key) (attr_value))
(shape_key) (dot) (attr_key) (attr_value)
(shape_key) (dot) (shape_key) (dot) (shape_key) (dot) (attr_key) (attr_value)
)
================================================================================
@ -53,7 +55,7 @@ foo.style.opacity: 5
--------------------------------------------------------------------------------
(source_file
(shape (identifier) (dot) (attr_key) (dot) (attr_key) (attr_value))
(shape_key) (dot) (attr_key) (dot) (attr_key) (attr_value)
)
================================================================================
@ -68,14 +70,12 @@ foo.style: {
--------------------------------------------------------------------------------
(source_file
(shape
(identifier) (dot) (attr_key)
(shape_key) (dot) (attr_key)
(block
(attr_key) (attr_value)
(attr_key) (attr_value)
)
)
)
================================================================================
Inline block style attributes
@ -86,18 +86,14 @@ foo.style: { opacity: 5 }
--------------------------------------------------------------------------------
(source_file
(shape
(identifier) (dot) (attr_key)
(shape_key) (dot) (attr_key)
(block
(attr_key) (attr_value)
(attr_key) (attr_value)
)
)
(shape
(identifier) (dot) (attr_key)
(shape_key) (dot) (attr_key)
(block
(attr_key) (attr_value)
)
)
)

View file

@ -10,24 +10,24 @@ biz<-baz
(source_file
(connection
(identifier)
(shape_key)
(arrow)
(identifier)
(shape_key)
)
(connection
(identifier)
(shape_key)
(arrow)
(identifier)
(shape_key)
)
(connection
(identifier)
(shape_key)
(arrow)
(identifier)
(shape_key)
)
(connection
(identifier)
(shape_key)
(arrow)
(identifier)
(shape_key)
)
)
@ -43,24 +43,24 @@ biz <- baz
(source_file
(connection
(identifier)
(shape_key)
(arrow)
(identifier)
(shape_key)
)
(connection
(identifier)
(shape_key)
(arrow)
(identifier)
(shape_key)
)
(connection
(identifier)
(shape_key)
(arrow)
(identifier)
(shape_key)
)
(connection
(identifier)
(shape_key)
(arrow)
(identifier)
(shape_key)
)
)
@ -75,14 +75,14 @@ Foo Bar -- Biz Baz
(source_file
(connection
(identifier)
(shape_key)
(arrow)
(identifier)
(shape_key)
)
(connection
(identifier)
(shape_key)
(arrow)
(identifier)
(shape_key)
)
)
@ -95,13 +95,13 @@ foo--bar->biz->baz
(source_file
(connection
(identifier)
(shape_key)
(arrow)
(identifier)
(shape_key)
(arrow)
(identifier)
(shape_key)
(arrow)
(identifier)
(shape_key)
)
)
@ -114,14 +114,14 @@ foo--bar;biz->baz
(source_file
(connection
(identifier)
(shape_key)
(arrow)
(identifier)
(shape_key)
)
(connection
(identifier)
(shape_key)
(arrow)
(identifier)
(shape_key)
)
)
@ -135,15 +135,31 @@ bar -> baz: Yes
(source_file
(connection
(identifier)
(shape_key)
(arrow)
(identifier)
(shape_key)
(label)
)
(connection
(identifier)
(shape_key)
(arrow)
(identifier)
(shape_key)
(label)
)
)
================================================================================
Connection using shape path
================================================================================
foo.biz.baz -> bar.baz.biz: Label
--------------------------------------------------------------------------------
(source_file
(connection
(shape_key) (dot) (shape_key) (dot) (shape_key)
(arrow)
(shape_key) (dot) (shape_key) (dot) (shape_key)
(label)
)
)

View file

@ -7,8 +7,8 @@ bar
--------------------------------------------------------------------------------
(source_file
(shape (identifier))
(shape (identifier))
(shape_key)
(shape_key)
)
================================================================================
@ -20,37 +20,43 @@ Complex identifier
--------------------------------------------------------------------------------
(source_file
(shape (identifier))
(shape (identifier))
(shape_key)
(shape_key)
)
================================================================================
Inline shapes
Declare a shape inside a container
================================================================================
foo.baz
--------------------------------------------------------------------------------
(source_file
(shape
(identifier)
(dot)
(identifier)
(shape_key) (dot) (shape_key)
)
)
================================================================================
Many shapes inline
Use quoted string as a shape key
================================================================================
'foo'.'baz'
--------------------------------------------------------------------------------
(source_file
(shape_key (string)) (dot) (shape_key (string))
)
================================================================================
Define multiple shapes using semicolons
================================================================================
a;b;c
--------------------------------------------------------------------------------
(source_file
(shape (identifier))
(shape (identifier))
(shape (identifier))
(shape_key)
(shape_key)
(shape_key)
)
================================================================================
@ -62,9 +68,9 @@ a: Foo Bar; b: Biz Baz
--------------------------------------------------------------------------------
(source_file
(shape (identifier) (label))
(shape (identifier) (label))
(shape (identifier) (label))
(shape_key) (label)
(shape_key) (label)
(shape_key) (label)
)
================================================================================
@ -78,9 +84,9 @@ bar : Foo Bar; baz
--------------------------------------------------------------------------------
(source_file
(shape (identifier))
(shape (identifier) (label))
(shape (identifier))
(shape_key)
(shape_key) (label)
(shape_key)
)
================================================================================
@ -98,13 +104,16 @@ foo: {
--------------------------------------------------------------------------------
(source_file
(shape (identifier) (block
(shape (identifier) (block
(shape (identifier) (block
(shape (identifier))
))
))
))
(shape_key)
(block
(shape_key)
(block
(shape_key)
(block
(shape_key)
)
)
)
)
================================================================================
@ -122,12 +131,15 @@ foo: Foo {
--------------------------------------------------------------------------------
(source_file
(shape (identifier) (label) (block
(shape (identifier) (label) (block
(shape (identifier) (label) (block
(shape (identifier) (label))
))
))
))
(shape_key) (label)
(block
(shape_key) (label)
(block
(shape_key) (label)
(block
(shape_key) (label)
)
)
)
)

View file

@ -4,7 +4,7 @@ direction: right;
# ^ string
# ^ punctuation.delimiter
shape: oval;
shape: oval
# <- error
# ^ error

View file

@ -1,8 +1,6 @@
foo.baz.biz
# <- variable
# ^ punctuation.delimiter
# ^ variable
# ^ punctuation.delimiter
# ^ variable
foo: Foo Bar

Binary file not shown.