cosmetic changes

This commit is contained in:
Dmitriy Pleshevskiy 2022-12-06 00:34:41 +03:00
parent a1bf1367fb
commit 78fe65f822
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
6 changed files with 62 additions and 52 deletions

View file

@ -1,12 +1,12 @@
module.exports = grammar({
name: "d2",
// TODO: handle empty lines
extras: ($) => [],
word: ($) => $._word,
rules: {
// TODO: add the actual grammar rules
source_file: ($) => repeat($._definition),
_definition: ($) => choice($._root_attribute, $.connection, $.shape),
@ -131,7 +131,8 @@ module.exports = grammar({
seq("`", repeat(token.immediate(/[^`\n]+/)), "`")
),
_end: ($) => choice(";", "\n", "\0"),
_eof: ($) => choice("\n", "\0"),
_end: ($) => choice(";", $._eof),
dot: ($) => ".",
},

View file

@ -689,6 +689,19 @@
}
]
},
"_eof": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "\n"
},
{
"type": "STRING",
"value": "\u0000"
}
]
},
"_end": {
"type": "CHOICE",
"members": [
@ -697,12 +710,8 @@
"value": ";"
},
{
"type": "STRING",
"value": "\n"
},
{
"type": "STRING",
"value": "\u0000"
"type": "SYMBOL",
"name": "_eof"
}
]
},

Binary file not shown.

View file

@ -1,33 +1,33 @@
==================
================================================================================
Root attribute
==================
================================================================================
direction: value
---
--------------------------------------------------------------------------------
(source_file
(attr_key) (attr_value)
)
==================
================================================================================
Inline shape attribute
==================
================================================================================
foo.shape: oval
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))
)
==================
================================================================================
Inline style attribute
==================
================================================================================
foo.style.opacity: 5
---
--------------------------------------------------------------------------------
(source_file
(shape (identifier) (dot) (attr_key) (dot) (attr_key) (attr_value))

View file

@ -1,12 +1,12 @@
==================
================================================================================
Simple connection
==================
================================================================================
foo--bar
biz->baz
biz<->baz
biz<-baz
---
--------------------------------------------------------------------------------
(source_file
(connection
@ -31,15 +31,15 @@ biz<-baz
)
)
==================
================================================================================
Formatted connection
==================
================================================================================
foo -- bar
biz -> baz
biz <-> baz
biz <- baz
---
--------------------------------------------------------------------------------
(source_file
(connection
@ -65,13 +65,13 @@ biz <- baz
)
=============================
================================================================================
Complex identifier connection
=============================
================================================================================
Foo Bar -- Biz Baz
-Bar-Foo- <- -Baz-Biz-
---
--------------------------------------------------------------------------------
(source_file
(connection
@ -86,12 +86,12 @@ Foo Bar -- Biz Baz
)
)
==================
================================================================================
Inline connection
==================
================================================================================
foo--bar->biz->baz
---
--------------------------------------------------------------------------------
(source_file
(connection
@ -105,12 +105,12 @@ foo--bar->biz->baz
)
)
==================
================================================================================
Many connections inline
==================
================================================================================
foo--bar;biz->baz
---
--------------------------------------------------------------------------------
(source_file
(connection
@ -125,13 +125,13 @@ foo--bar;biz->baz
)
)
==================
Descripted connection
==================
================================================================================
Labeled connections
================================================================================
foo--bar: Question?
bar -> baz: Yes
---
--------------------------------------------------------------------------------
(source_file
(connection

View file

@ -1,35 +1,35 @@
==================
================================================================================
Simple shape
==================
================================================================================
foo
bar
---
--------------------------------------------------------------------------------
(source_file
(shape (identifier))
(shape (identifier))
)
==================
================================================================================
Complex identifier
==================
================================================================================
Foo bar
-Biz-baz-
---
--------------------------------------------------------------------------------
(source_file
(shape (identifier))
(shape (identifier))
)
==================
================================================================================
Inline shapes
==================
================================================================================
foo.baz
---
--------------------------------------------------------------------------------
(source_file
(shape
@ -40,12 +40,12 @@ foo.baz
)
==================
================================================================================
Many shapes inline
==================
================================================================================
a;b;c
---
--------------------------------------------------------------------------------
(source_file
(shape (identifier))
@ -53,13 +53,13 @@ a;b;c
(shape (identifier))
)
==================
================================================================================
Aliased shapes
==================
================================================================================
a: Foo Bar
a: Foo Bar; b: Biz Baz
---
--------------------------------------------------------------------------------
(source_file
(shape (identifier) (label))