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 b

View file

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

View file

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

View file

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

View file

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

Binary file not shown.

View file

@ -23,12 +23,14 @@ foo: {
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(source_file (source_file
(shape (identifier) (block (shape_key)
(block
(attr_key) (attr_value) (attr_key) (attr_value)
(shape (identifier) (dot) (identifier) (dot) (identifier) (block (shape_key) (dot) (shape_key) (dot) (shape_key)
(block
(attr_key) (attr_value) (attr_key) (attr_value)
)) )
)) )
) )
@ -41,8 +43,8 @@ foo.bar.baz.shape: oval
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(source_file (source_file
(shape (identifier) (dot) (attr_key) (attr_value)) (shape_key) (dot) (attr_key) (attr_value)
(shape (identifier) (dot) (identifier) (dot) (identifier) (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 (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 (source_file
(shape (shape_key) (dot) (attr_key)
(identifier) (dot) (attr_key)
(block (block
(attr_key) (attr_value) (attr_key) (attr_value)
(attr_key) (attr_value) (attr_key) (attr_value)
) )
) )
)
================================================================================ ================================================================================
Inline block style attributes Inline block style attributes
@ -86,18 +86,14 @@ foo.style: { opacity: 5 }
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(source_file (source_file
(shape (shape_key) (dot) (attr_key)
(identifier) (dot) (attr_key)
(block (block
(attr_key) (attr_value) (attr_key) (attr_value)
(attr_key) (attr_value) (attr_key) (attr_value)
) )
) (shape_key) (dot) (attr_key)
(shape
(identifier) (dot) (attr_key)
(block (block
(attr_key) (attr_value) (attr_key) (attr_value)
) )
) )
)

View file

@ -10,24 +10,24 @@ biz<-baz
(source_file (source_file
(connection (connection
(identifier) (shape_key)
(arrow) (arrow)
(identifier) (shape_key)
) )
(connection (connection
(identifier) (shape_key)
(arrow) (arrow)
(identifier) (shape_key)
) )
(connection (connection
(identifier) (shape_key)
(arrow) (arrow)
(identifier) (shape_key)
) )
(connection (connection
(identifier) (shape_key)
(arrow) (arrow)
(identifier) (shape_key)
) )
) )
@ -43,24 +43,24 @@ biz <- baz
(source_file (source_file
(connection (connection
(identifier) (shape_key)
(arrow) (arrow)
(identifier) (shape_key)
) )
(connection (connection
(identifier) (shape_key)
(arrow) (arrow)
(identifier) (shape_key)
) )
(connection (connection
(identifier) (shape_key)
(arrow) (arrow)
(identifier) (shape_key)
) )
(connection (connection
(identifier) (shape_key)
(arrow) (arrow)
(identifier) (shape_key)
) )
) )
@ -75,14 +75,14 @@ Foo Bar -- Biz Baz
(source_file (source_file
(connection (connection
(identifier) (shape_key)
(arrow) (arrow)
(identifier) (shape_key)
) )
(connection (connection
(identifier) (shape_key)
(arrow) (arrow)
(identifier) (shape_key)
) )
) )
@ -95,13 +95,13 @@ foo--bar->biz->baz
(source_file (source_file
(connection (connection
(identifier) (shape_key)
(arrow) (arrow)
(identifier) (shape_key)
(arrow) (arrow)
(identifier) (shape_key)
(arrow) (arrow)
(identifier) (shape_key)
) )
) )
@ -114,14 +114,14 @@ foo--bar;biz->baz
(source_file (source_file
(connection (connection
(identifier) (shape_key)
(arrow) (arrow)
(identifier) (shape_key)
) )
(connection (connection
(identifier) (shape_key)
(arrow) (arrow)
(identifier) (shape_key)
) )
) )
@ -135,15 +135,31 @@ bar -> baz: Yes
(source_file (source_file
(connection (connection
(identifier) (shape_key)
(arrow) (arrow)
(identifier) (shape_key)
(label) (label)
) )
(connection (connection
(identifier) (shape_key)
(arrow) (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) (label)
) )
) )

View file

@ -7,8 +7,8 @@ bar
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(source_file (source_file
(shape (identifier)) (shape_key)
(shape (identifier)) (shape_key)
) )
================================================================================ ================================================================================
@ -20,37 +20,43 @@ Complex identifier
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(source_file (source_file
(shape (identifier)) (shape_key)
(shape (identifier)) (shape_key)
) )
================================================================================ ================================================================================
Inline shapes Declare a shape inside a container
================================================================================ ================================================================================
foo.baz foo.baz
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(source_file (source_file
(shape (shape_key) (dot) (shape_key)
(identifier)
(dot)
(identifier)
) )
)
================================================================================ ================================================================================
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 a;b;c
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(source_file (source_file
(shape (identifier)) (shape_key)
(shape (identifier)) (shape_key)
(shape (identifier)) (shape_key)
) )
================================================================================ ================================================================================
@ -62,9 +68,9 @@ a: Foo Bar; b: Biz Baz
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(source_file (source_file
(shape (identifier) (label)) (shape_key) (label)
(shape (identifier) (label)) (shape_key) (label)
(shape (identifier) (label)) (shape_key) (label)
) )
================================================================================ ================================================================================
@ -78,9 +84,9 @@ bar : Foo Bar; baz
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(source_file (source_file
(shape (identifier)) (shape_key)
(shape (identifier) (label)) (shape_key) (label)
(shape (identifier)) (shape_key)
) )
================================================================================ ================================================================================
@ -98,13 +104,16 @@ foo: {
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(source_file (source_file
(shape (identifier) (block (shape_key)
(shape (identifier) (block (block
(shape (identifier) (block (shape_key)
(shape (identifier)) (block
)) (shape_key)
)) (block
)) (shape_key)
)
)
)
) )
================================================================================ ================================================================================
@ -122,12 +131,15 @@ foo: Foo {
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(source_file (source_file
(shape (identifier) (label) (block (shape_key) (label)
(shape (identifier) (label) (block (block
(shape (identifier) (label) (block (shape_key) (label)
(shape (identifier) (label)) (block
)) (shape_key) (label)
)) (block
)) (shape_key) (label)
)
)
)
) )

View file

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

View file

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

Binary file not shown.