cosmetic changes
This commit is contained in:
parent
a1bf1367fb
commit
78fe65f822
6 changed files with 62 additions and 52 deletions
|
@ -1,12 +1,12 @@
|
||||||
module.exports = grammar({
|
module.exports = grammar({
|
||||||
name: "d2",
|
name: "d2",
|
||||||
|
|
||||||
|
// TODO: handle empty lines
|
||||||
extras: ($) => [],
|
extras: ($) => [],
|
||||||
|
|
||||||
word: ($) => $._word,
|
word: ($) => $._word,
|
||||||
|
|
||||||
rules: {
|
rules: {
|
||||||
// TODO: add the actual grammar rules
|
|
||||||
source_file: ($) => repeat($._definition),
|
source_file: ($) => repeat($._definition),
|
||||||
|
|
||||||
_definition: ($) => choice($._root_attribute, $.connection, $.shape),
|
_definition: ($) => choice($._root_attribute, $.connection, $.shape),
|
||||||
|
@ -131,7 +131,8 @@ module.exports = grammar({
|
||||||
seq("`", repeat(token.immediate(/[^`\n]+/)), "`")
|
seq("`", repeat(token.immediate(/[^`\n]+/)), "`")
|
||||||
),
|
),
|
||||||
|
|
||||||
_end: ($) => choice(";", "\n", "\0"),
|
_eof: ($) => choice("\n", "\0"),
|
||||||
|
_end: ($) => choice(";", $._eof),
|
||||||
|
|
||||||
dot: ($) => ".",
|
dot: ($) => ".",
|
||||||
},
|
},
|
||||||
|
|
|
@ -689,6 +689,19 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"_eof": {
|
||||||
|
"type": "CHOICE",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "\n"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "\u0000"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"_end": {
|
"_end": {
|
||||||
"type": "CHOICE",
|
"type": "CHOICE",
|
||||||
"members": [
|
"members": [
|
||||||
|
@ -697,12 +710,8 @@
|
||||||
"value": ";"
|
"value": ";"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "STRING",
|
"type": "SYMBOL",
|
||||||
"value": "\n"
|
"name": "_eof"
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "STRING",
|
|
||||||
"value": "\u0000"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
BIN
src/parser.c
BIN
src/parser.c
Binary file not shown.
|
@ -1,33 +1,33 @@
|
||||||
==================
|
================================================================================
|
||||||
Root attribute
|
Root attribute
|
||||||
==================
|
================================================================================
|
||||||
direction: value
|
direction: value
|
||||||
|
|
||||||
---
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
(source_file
|
(source_file
|
||||||
(attr_key) (attr_value)
|
(attr_key) (attr_value)
|
||||||
)
|
)
|
||||||
|
|
||||||
==================
|
================================================================================
|
||||||
Inline shape attribute
|
Inline shape attribute
|
||||||
==================
|
================================================================================
|
||||||
foo.shape: oval
|
foo.shape: oval
|
||||||
foo.bar.baz.shape: oval
|
foo.bar.baz.shape: oval
|
||||||
|
|
||||||
---
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
(source_file
|
(source_file
|
||||||
(shape (identifier) (dot) (attr_key) (attr_value))
|
(shape (identifier) (dot) (attr_key) (attr_value))
|
||||||
(shape (identifier) (dot) (identifier) (dot) (identifier) (dot) (attr_key) (attr_value))
|
(shape (identifier) (dot) (identifier) (dot) (identifier) (dot) (attr_key) (attr_value))
|
||||||
)
|
)
|
||||||
|
|
||||||
==================
|
================================================================================
|
||||||
Inline style attribute
|
Inline style attribute
|
||||||
==================
|
================================================================================
|
||||||
foo.style.opacity: 5
|
foo.style.opacity: 5
|
||||||
|
|
||||||
---
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
(source_file
|
(source_file
|
||||||
(shape (identifier) (dot) (attr_key) (dot) (attr_key) (attr_value))
|
(shape (identifier) (dot) (attr_key) (dot) (attr_key) (attr_value))
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
==================
|
================================================================================
|
||||||
Simple connection
|
Simple connection
|
||||||
==================
|
================================================================================
|
||||||
foo--bar
|
foo--bar
|
||||||
biz->baz
|
biz->baz
|
||||||
biz<->baz
|
biz<->baz
|
||||||
biz<-baz
|
biz<-baz
|
||||||
|
|
||||||
---
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
(source_file
|
(source_file
|
||||||
(connection
|
(connection
|
||||||
|
@ -31,15 +31,15 @@ biz<-baz
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
==================
|
================================================================================
|
||||||
Formatted connection
|
Formatted connection
|
||||||
==================
|
================================================================================
|
||||||
foo -- bar
|
foo -- bar
|
||||||
biz -> baz
|
biz -> baz
|
||||||
biz <-> baz
|
biz <-> baz
|
||||||
biz <- baz
|
biz <- baz
|
||||||
|
|
||||||
---
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
(source_file
|
(source_file
|
||||||
(connection
|
(connection
|
||||||
|
@ -65,13 +65,13 @@ biz <- baz
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
=============================
|
================================================================================
|
||||||
Complex identifier connection
|
Complex identifier connection
|
||||||
=============================
|
================================================================================
|
||||||
Foo Bar -- Biz Baz
|
Foo Bar -- Biz Baz
|
||||||
-Bar-Foo- <- -Baz-Biz-
|
-Bar-Foo- <- -Baz-Biz-
|
||||||
|
|
||||||
---
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
(source_file
|
(source_file
|
||||||
(connection
|
(connection
|
||||||
|
@ -86,12 +86,12 @@ Foo Bar -- Biz Baz
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
==================
|
================================================================================
|
||||||
Inline connection
|
Inline connection
|
||||||
==================
|
================================================================================
|
||||||
foo--bar->biz->baz
|
foo--bar->biz->baz
|
||||||
|
|
||||||
---
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
(source_file
|
(source_file
|
||||||
(connection
|
(connection
|
||||||
|
@ -105,12 +105,12 @@ foo--bar->biz->baz
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
==================
|
================================================================================
|
||||||
Many connections inline
|
Many connections inline
|
||||||
==================
|
================================================================================
|
||||||
foo--bar;biz->baz
|
foo--bar;biz->baz
|
||||||
|
|
||||||
---
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
(source_file
|
(source_file
|
||||||
(connection
|
(connection
|
||||||
|
@ -125,13 +125,13 @@ foo--bar;biz->baz
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
==================
|
================================================================================
|
||||||
Descripted connection
|
Labeled connections
|
||||||
==================
|
================================================================================
|
||||||
foo--bar: Question?
|
foo--bar: Question?
|
||||||
bar->baz: Yes
|
bar -> baz: Yes
|
||||||
|
|
||||||
---
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
(source_file
|
(source_file
|
||||||
(connection
|
(connection
|
||||||
|
|
|
@ -1,35 +1,35 @@
|
||||||
==================
|
================================================================================
|
||||||
Simple shape
|
Simple shape
|
||||||
==================
|
================================================================================
|
||||||
foo
|
foo
|
||||||
bar
|
bar
|
||||||
|
|
||||||
---
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
(source_file
|
(source_file
|
||||||
(shape (identifier))
|
(shape (identifier))
|
||||||
(shape (identifier))
|
(shape (identifier))
|
||||||
)
|
)
|
||||||
|
|
||||||
==================
|
================================================================================
|
||||||
Complex identifier
|
Complex identifier
|
||||||
==================
|
================================================================================
|
||||||
Foo bar
|
Foo bar
|
||||||
-Biz-baz-
|
-Biz-baz-
|
||||||
|
|
||||||
---
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
(source_file
|
(source_file
|
||||||
(shape (identifier))
|
(shape (identifier))
|
||||||
(shape (identifier))
|
(shape (identifier))
|
||||||
)
|
)
|
||||||
|
|
||||||
==================
|
================================================================================
|
||||||
Inline shapes
|
Inline shapes
|
||||||
==================
|
================================================================================
|
||||||
foo.baz
|
foo.baz
|
||||||
|
|
||||||
---
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
(source_file
|
(source_file
|
||||||
(shape
|
(shape
|
||||||
|
@ -40,12 +40,12 @@ foo.baz
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
==================
|
================================================================================
|
||||||
Many shapes inline
|
Many shapes inline
|
||||||
==================
|
================================================================================
|
||||||
a;b;c
|
a;b;c
|
||||||
|
|
||||||
---
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
(source_file
|
(source_file
|
||||||
(shape (identifier))
|
(shape (identifier))
|
||||||
|
@ -53,13 +53,13 @@ a;b;c
|
||||||
(shape (identifier))
|
(shape (identifier))
|
||||||
)
|
)
|
||||||
|
|
||||||
==================
|
================================================================================
|
||||||
Aliased shapes
|
Aliased shapes
|
||||||
==================
|
================================================================================
|
||||||
a: Foo Bar
|
a: Foo Bar
|
||||||
a: Foo Bar; b: Biz Baz
|
a: Foo Bar; b: Biz Baz
|
||||||
|
|
||||||
---
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
(source_file
|
(source_file
|
||||||
(shape (identifier) (label))
|
(shape (identifier) (label))
|
||||||
|
|
Loading…
Reference in a new issue