diff --git a/d2ast/d2ast.go b/d2ast/d2ast.go
index b0e9386e9..bd5ab4f82 100644
--- a/d2ast/d2ast.go
+++ b/d2ast/d2ast.go
@@ -55,6 +55,7 @@ type Node interface {
var _ Node = &Comment{}
var _ Node = &BlockComment{}
+var _ Node = &NotNull{}
var _ Node = &Null{}
var _ Node = &Boolean{}
var _ Node = &Number{}
@@ -328,6 +329,7 @@ type Scalar interface {
}
// See String for rest.
+var _ Scalar = &NotNull{}
var _ Scalar = &Null{}
var _ Scalar = &Boolean{}
var _ Scalar = &Number{}
@@ -349,6 +351,7 @@ var _ String = &BlockString{}
func (c *Comment) node() {}
func (c *BlockComment) node() {}
func (n *Null) node() {}
+func (n *NotNull) node() {}
func (b *Boolean) node() {}
func (n *Number) node() {}
func (s *UnquotedString) node() {}
@@ -367,6 +370,7 @@ func (i *EdgeIndex) node() {}
func (c *Comment) Type() string { return "comment" }
func (c *BlockComment) Type() string { return "block comment" }
func (n *Null) Type() string { return "null" }
+func (n *NotNull) Type() string { return "!null" }
func (b *Boolean) Type() string { return "boolean" }
func (n *Number) Type() string { return "number" }
func (s *UnquotedString) Type() string { return "unquoted string" }
@@ -385,6 +389,7 @@ func (i *EdgeIndex) Type() string { return "edge index" }
func (c *Comment) GetRange() Range { return c.Range }
func (c *BlockComment) GetRange() Range { return c.Range }
func (n *Null) GetRange() Range { return n.Range }
+func (n *NotNull) GetRange() Range { return n.Range }
func (b *Boolean) GetRange() Range { return b.Range }
func (n *Number) GetRange() Range { return n.Range }
func (s *UnquotedString) GetRange() Range { return s.Range }
@@ -409,6 +414,7 @@ func (i *Import) mapNode() {}
func (c *Comment) arrayNode() {}
func (c *BlockComment) arrayNode() {}
func (n *Null) arrayNode() {}
+func (n *NotNull) arrayNode() {}
func (b *Boolean) arrayNode() {}
func (n *Number) arrayNode() {}
func (s *UnquotedString) arrayNode() {}
@@ -421,6 +427,7 @@ func (a *Array) arrayNode() {}
func (m *Map) arrayNode() {}
func (n *Null) value() {}
+func (n *NotNull) value() {}
func (b *Boolean) value() {}
func (n *Number) value() {}
func (s *UnquotedString) value() {}
@@ -432,6 +439,7 @@ func (m *Map) value() {}
func (i *Import) value() {}
func (n *Null) scalar() {}
+func (n *NotNull) scalar() {}
func (b *Boolean) scalar() {}
func (n *Number) scalar() {}
func (s *UnquotedString) scalar() {}
@@ -442,6 +450,7 @@ func (s *BlockString) scalar() {}
func (c *Comment) Children() []Node { return nil }
func (c *BlockComment) Children() []Node { return nil }
func (n *Null) Children() []Node { return nil }
+func (n *NotNull) Children() []Node { return nil }
func (b *Boolean) Children() []Node { return nil }
func (n *Number) Children() []Node { return nil }
func (s *SingleQuotedString) Children() []Node { return nil }
@@ -574,6 +583,7 @@ func Walk(node Node, fn func(Node) bool) {
// TODO: mistake, move into parse.go
func (n *Null) ScalarString() string { return "" }
+func (n *NotNull) ScalarString() string { return "" }
func (b *Boolean) ScalarString() string { return strconv.FormatBool(b.Value) }
func (n *Number) ScalarString() string { return n.Raw }
func (s *UnquotedString) ScalarString() string {
@@ -631,6 +641,10 @@ type Null struct {
Range Range `json:"range"`
}
+type NotNull struct {
+ Range Range `json:"range"`
+}
+
type Boolean struct {
Range Range `json:"range"`
Value bool `json:"value"`
@@ -1368,6 +1382,7 @@ func (ab ArrayNodeBox) Unbox() ArrayNode {
// ValueBox is used to box Value for JSON persistence.
type ValueBox struct {
+ NotNull *NotNull `json:"notNull,omitempty"`
Null *Null `json:"null,omitempty"`
Boolean *Boolean `json:"boolean,omitempty"`
Number *Number `json:"number,omitempty"`
@@ -1384,6 +1399,8 @@ func (vb ValueBox) Unbox() Value {
switch {
case vb.Null != nil:
return vb.Null
+ case vb.NotNull != nil:
+ return vb.NotNull
case vb.Boolean != nil:
return vb.Boolean
case vb.Number != nil:
@@ -1412,6 +1429,8 @@ func MakeValueBox(v Value) ValueBox {
switch v := v.(type) {
case *Null:
vb.Null = v
+ case *NotNull:
+ vb.NotNull = v
case *Boolean:
vb.Boolean = v
case *Number:
@@ -1437,6 +1456,7 @@ func MakeValueBox(v Value) ValueBox {
func (vb ValueBox) ScalarBox() ScalarBox {
var sb ScalarBox
sb.Null = vb.Null
+ sb.NotNull = vb.NotNull
sb.Boolean = vb.Boolean
sb.Number = vb.Number
sb.UnquotedString = vb.UnquotedString
@@ -1459,6 +1479,7 @@ func (vb ValueBox) StringBox() *StringBox {
// TODO: implement ScalarString()
type ScalarBox struct {
Null *Null `json:"null,omitempty"`
+ NotNull *NotNull `json:"notNull,omitempty"`
Boolean *Boolean `json:"boolean,omitempty"`
Number *Number `json:"number,omitempty"`
UnquotedString *UnquotedString `json:"unquoted_string,omitempty"`
@@ -1471,6 +1492,8 @@ func (sb ScalarBox) Unbox() Scalar {
switch {
case sb.Null != nil:
return sb.Null
+ case sb.NotNull != nil:
+ return sb.NotNull
case sb.Boolean != nil:
return sb.Boolean
case sb.Number != nil:
@@ -1559,7 +1582,7 @@ func RawString(s string, inKey bool) String {
return &SingleQuotedString{Value: s}
}
}
- } else if s == "null" || strings.ContainsAny(s, UnquotedValueSpecials) {
+ } else if s == "null" || s == "!null" || strings.ContainsAny(s, UnquotedValueSpecials) {
if !strings.ContainsRune(s, '"') && !strings.ContainsRune(s, '$') {
return FlatDoubleQuotedString(s)
}
diff --git a/d2format/format.go b/d2format/format.go
index 1fe745c1d..d24fa5f5d 100644
--- a/d2format/format.go
+++ b/d2format/format.go
@@ -42,6 +42,8 @@ func (p *printer) node(n d2ast.Node) {
p.blockComment(n)
case *d2ast.Null:
p.sb.WriteString("null")
+ case *d2ast.NotNull:
+ p.sb.WriteString("!null")
case *d2ast.Boolean:
p.sb.WriteString(strconv.FormatBool(n.Value))
case *d2ast.Number:
diff --git a/d2parser/parse.go b/d2parser/parse.go
index 3eb500484..e4a6caf41 100644
--- a/d2parser/parse.go
+++ b/d2parser/parse.go
@@ -1669,6 +1669,13 @@ func (p *parser) parseValue() d2ast.ValueBox {
return box
}
+ if strings.EqualFold(s.ScalarString(), "!null") {
+ box.NotNull = &d2ast.NotNull{
+ Range: s.Range,
+ }
+ return box
+ }
+
if strings.EqualFold(s.ScalarString(), "true") {
box.Boolean = &d2ast.Boolean{
Range: s.Range,
diff --git a/e2etests/testdata/txtar/model-nulling/dagre/board.exp.json b/e2etests/testdata/txtar/model-nulling/dagre/board.exp.json
index 92915fc79..d36039885 100644
--- a/e2etests/testdata/txtar/model-nulling/dagre/board.exp.json
+++ b/e2etests/testdata/txtar/model-nulling/dagre/board.exp.json
@@ -16,7 +16,7 @@
"type": "rectangle",
"pos": {
"x": 0,
- "y": 50
+ "y": 67
},
"width": 80,
"height": 66,
@@ -58,7 +58,7 @@
"type": "rectangle",
"pos": {
"x": 130,
- "y": 20
+ "y": 37
},
"width": 123,
"height": 126,
@@ -100,7 +100,7 @@
"type": "rectangle",
"pos": {
"x": 160,
- "y": 50
+ "y": 67
},
"width": 63,
"height": 66,
@@ -141,8 +141,8 @@
"id": "a",
"type": "rectangle",
"pos": {
- "x": 303,
- "y": 50
+ "x": 463,
+ "y": 67
},
"width": 53,
"height": 66,
@@ -183,8 +183,8 @@
"id": "b",
"type": "rectangle",
"pos": {
- "x": 303,
- "y": 266
+ "x": 463,
+ "y": 300
},
"width": 53,
"height": 66,
@@ -220,6 +220,47 @@
"labelPosition": "INSIDE_MIDDLE_CENTER",
"zIndex": 0,
"level": 1
+ },
+ {
+ "id": "user",
+ "type": "rectangle",
+ "pos": {
+ "x": 303,
+ "y": 50
+ },
+ "width": 100,
+ "height": 100,
+ "opacity": 1,
+ "strokeDash": 0,
+ "strokeWidth": 2,
+ "borderRadius": 0,
+ "fill": "B6",
+ "stroke": "B1",
+ "animated": false,
+ "shadow": false,
+ "3d": false,
+ "multiple": false,
+ "double-border": false,
+ "tooltip": "",
+ "link": "",
+ "icon": null,
+ "iconPosition": "",
+ "blend": false,
+ "fields": null,
+ "methods": null,
+ "columns": null,
+ "label": "",
+ "fontSize": 16,
+ "fontFamily": "DEFAULT",
+ "language": "",
+ "color": "N1",
+ "italic": false,
+ "bold": true,
+ "underline": false,
+ "labelWidth": 0,
+ "labelHeight": 0,
+ "zIndex": 0,
+ "level": 1
}
],
"connections": [
@@ -249,20 +290,20 @@
"link": "",
"route": [
{
- "x": 329.5,
- "y": 116
+ "x": 489.5,
+ "y": 133
},
{
- "x": 329.5,
- "y": 156
+ "x": 489.5,
+ "y": 186.60000610351562
},
{
- "x": 329.5,
- "y": 226
+ "x": 489.5,
+ "y": 260
},
{
- "x": 329.5,
- "y": 266
+ "x": 489.5,
+ "y": 300
}
],
"isCurve": true,
diff --git a/e2etests/testdata/txtar/model-nulling/dagre/sketch.exp.svg b/e2etests/testdata/txtar/model-nulling/dagre/sketch.exp.svg
index 833c578d5..275e0b82f 100644
--- a/e2etests/testdata/txtar/model-nulling/dagre/sketch.exp.svg
+++ b/e2etests/testdata/txtar/model-nulling/dagre/sketch.exp.svg
@@ -1,16 +1,16 @@
-
\ No newline at end of file
diff --git a/e2etests/testdata/txtar/model-nulling/elk/board.exp.json b/e2etests/testdata/txtar/model-nulling/elk/board.exp.json
index 15d161ccf..1175c326a 100644
--- a/e2etests/testdata/txtar/model-nulling/elk/board.exp.json
+++ b/e2etests/testdata/txtar/model-nulling/elk/board.exp.json
@@ -220,6 +220,47 @@
"labelPosition": "INSIDE_MIDDLE_CENTER",
"zIndex": 0,
"level": 1
+ },
+ {
+ "id": "user",
+ "type": "rectangle",
+ "pos": {
+ "x": 368,
+ "y": 45
+ },
+ "width": 100,
+ "height": 100,
+ "opacity": 1,
+ "strokeDash": 0,
+ "strokeWidth": 2,
+ "borderRadius": 0,
+ "fill": "B6",
+ "stroke": "B1",
+ "animated": false,
+ "shadow": false,
+ "3d": false,
+ "multiple": false,
+ "double-border": false,
+ "tooltip": "",
+ "link": "",
+ "icon": null,
+ "iconPosition": "",
+ "blend": false,
+ "fields": null,
+ "methods": null,
+ "columns": null,
+ "label": "",
+ "fontSize": 16,
+ "fontFamily": "DEFAULT",
+ "language": "",
+ "color": "N1",
+ "italic": false,
+ "bold": true,
+ "underline": false,
+ "labelWidth": 0,
+ "labelHeight": 0,
+ "zIndex": 0,
+ "level": 1
}
],
"connections": [
diff --git a/e2etests/testdata/txtar/model-nulling/elk/sketch.exp.svg b/e2etests/testdata/txtar/model-nulling/elk/sketch.exp.svg
index 1bad0a97a..ca9dadd55 100644
--- a/e2etests/testdata/txtar/model-nulling/elk/sketch.exp.svg
+++ b/e2etests/testdata/txtar/model-nulling/elk/sketch.exp.svg
@@ -1,16 +1,16 @@
-helloyesabok
-
+ .d2-723805646 .fill-N1{fill:#0A0F25;}
+ .d2-723805646 .fill-N2{fill:#676C7E;}
+ .d2-723805646 .fill-N3{fill:#9499AB;}
+ .d2-723805646 .fill-N4{fill:#CFD2DD;}
+ .d2-723805646 .fill-N5{fill:#DEE1EB;}
+ .d2-723805646 .fill-N6{fill:#EEF1F8;}
+ .d2-723805646 .fill-N7{fill:#FFFFFF;}
+ .d2-723805646 .fill-B1{fill:#0D32B2;}
+ .d2-723805646 .fill-B2{fill:#0D32B2;}
+ .d2-723805646 .fill-B3{fill:#E3E9FD;}
+ .d2-723805646 .fill-B4{fill:#E3E9FD;}
+ .d2-723805646 .fill-B5{fill:#EDF0FD;}
+ .d2-723805646 .fill-B6{fill:#F7F8FE;}
+ .d2-723805646 .fill-AA2{fill:#4A6FF3;}
+ .d2-723805646 .fill-AA4{fill:#EDF0FD;}
+ .d2-723805646 .fill-AA5{fill:#F7F8FE;}
+ .d2-723805646 .fill-AB4{fill:#EDF0FD;}
+ .d2-723805646 .fill-AB5{fill:#F7F8FE;}
+ .d2-723805646 .stroke-N1{stroke:#0A0F25;}
+ .d2-723805646 .stroke-N2{stroke:#676C7E;}
+ .d2-723805646 .stroke-N3{stroke:#9499AB;}
+ .d2-723805646 .stroke-N4{stroke:#CFD2DD;}
+ .d2-723805646 .stroke-N5{stroke:#DEE1EB;}
+ .d2-723805646 .stroke-N6{stroke:#EEF1F8;}
+ .d2-723805646 .stroke-N7{stroke:#FFFFFF;}
+ .d2-723805646 .stroke-B1{stroke:#0D32B2;}
+ .d2-723805646 .stroke-B2{stroke:#0D32B2;}
+ .d2-723805646 .stroke-B3{stroke:#E3E9FD;}
+ .d2-723805646 .stroke-B4{stroke:#E3E9FD;}
+ .d2-723805646 .stroke-B5{stroke:#EDF0FD;}
+ .d2-723805646 .stroke-B6{stroke:#F7F8FE;}
+ .d2-723805646 .stroke-AA2{stroke:#4A6FF3;}
+ .d2-723805646 .stroke-AA4{stroke:#EDF0FD;}
+ .d2-723805646 .stroke-AA5{stroke:#F7F8FE;}
+ .d2-723805646 .stroke-AB4{stroke:#EDF0FD;}
+ .d2-723805646 .stroke-AB5{stroke:#F7F8FE;}
+ .d2-723805646 .background-color-N1{background-color:#0A0F25;}
+ .d2-723805646 .background-color-N2{background-color:#676C7E;}
+ .d2-723805646 .background-color-N3{background-color:#9499AB;}
+ .d2-723805646 .background-color-N4{background-color:#CFD2DD;}
+ .d2-723805646 .background-color-N5{background-color:#DEE1EB;}
+ .d2-723805646 .background-color-N6{background-color:#EEF1F8;}
+ .d2-723805646 .background-color-N7{background-color:#FFFFFF;}
+ .d2-723805646 .background-color-B1{background-color:#0D32B2;}
+ .d2-723805646 .background-color-B2{background-color:#0D32B2;}
+ .d2-723805646 .background-color-B3{background-color:#E3E9FD;}
+ .d2-723805646 .background-color-B4{background-color:#E3E9FD;}
+ .d2-723805646 .background-color-B5{background-color:#EDF0FD;}
+ .d2-723805646 .background-color-B6{background-color:#F7F8FE;}
+ .d2-723805646 .background-color-AA2{background-color:#4A6FF3;}
+ .d2-723805646 .background-color-AA4{background-color:#EDF0FD;}
+ .d2-723805646 .background-color-AA5{background-color:#F7F8FE;}
+ .d2-723805646 .background-color-AB4{background-color:#EDF0FD;}
+ .d2-723805646 .background-color-AB5{background-color:#F7F8FE;}
+ .d2-723805646 .color-N1{color:#0A0F25;}
+ .d2-723805646 .color-N2{color:#676C7E;}
+ .d2-723805646 .color-N3{color:#9499AB;}
+ .d2-723805646 .color-N4{color:#CFD2DD;}
+ .d2-723805646 .color-N5{color:#DEE1EB;}
+ .d2-723805646 .color-N6{color:#EEF1F8;}
+ .d2-723805646 .color-N7{color:#FFFFFF;}
+ .d2-723805646 .color-B1{color:#0D32B2;}
+ .d2-723805646 .color-B2{color:#0D32B2;}
+ .d2-723805646 .color-B3{color:#E3E9FD;}
+ .d2-723805646 .color-B4{color:#E3E9FD;}
+ .d2-723805646 .color-B5{color:#EDF0FD;}
+ .d2-723805646 .color-B6{color:#F7F8FE;}
+ .d2-723805646 .color-AA2{color:#4A6FF3;}
+ .d2-723805646 .color-AA4{color:#EDF0FD;}
+ .d2-723805646 .color-AA5{color:#F7F8FE;}
+ .d2-723805646 .color-AB4{color:#EDF0FD;}
+ .d2-723805646 .color-AB5{color:#F7F8FE;}.appendix text.text{fill:#0A0F25}.md{--color-fg-default:#0A0F25;--color-fg-muted:#676C7E;--color-fg-subtle:#9499AB;--color-canvas-default:#FFFFFF;--color-canvas-subtle:#EEF1F8;--color-border-default:#0D32B2;--color-border-muted:#0D32B2;--color-neutral-muted:#EEF1F8;--color-accent-fg:#0D32B2;--color-accent-emphasis:#0D32B2;--color-attention-subtle:#676C7E;--color-danger-fg:red;}.sketch-overlay-B1{fill:url(#streaks-darker-d2-723805646);mix-blend-mode:lighten}.sketch-overlay-B2{fill:url(#streaks-darker-d2-723805646);mix-blend-mode:lighten}.sketch-overlay-B3{fill:url(#streaks-bright-d2-723805646);mix-blend-mode:darken}.sketch-overlay-B4{fill:url(#streaks-bright-d2-723805646);mix-blend-mode:darken}.sketch-overlay-B5{fill:url(#streaks-bright-d2-723805646);mix-blend-mode:darken}.sketch-overlay-B6{fill:url(#streaks-bright-d2-723805646);mix-blend-mode:darken}.sketch-overlay-AA2{fill:url(#streaks-dark-d2-723805646);mix-blend-mode:overlay}.sketch-overlay-AA4{fill:url(#streaks-bright-d2-723805646);mix-blend-mode:darken}.sketch-overlay-AA5{fill:url(#streaks-bright-d2-723805646);mix-blend-mode:darken}.sketch-overlay-AB4{fill:url(#streaks-bright-d2-723805646);mix-blend-mode:darken}.sketch-overlay-AB5{fill:url(#streaks-bright-d2-723805646);mix-blend-mode:darken}.sketch-overlay-N1{fill:url(#streaks-darker-d2-723805646);mix-blend-mode:lighten}.sketch-overlay-N2{fill:url(#streaks-dark-d2-723805646);mix-blend-mode:overlay}.sketch-overlay-N3{fill:url(#streaks-normal-d2-723805646);mix-blend-mode:color-burn}.sketch-overlay-N4{fill:url(#streaks-normal-d2-723805646);mix-blend-mode:color-burn}.sketch-overlay-N5{fill:url(#streaks-bright-d2-723805646);mix-blend-mode:darken}.sketch-overlay-N6{fill:url(#streaks-bright-d2-723805646);mix-blend-mode:darken}.sketch-overlay-N7{fill:url(#streaks-bright-d2-723805646);mix-blend-mode:darken}.light-code{display: block}.dark-code{display: none}]]>helloyesabok
+
diff --git a/e2etests/txtar.txt b/e2etests/txtar.txt
index 63ca40aec..a8fd32c81 100644
--- a/e2etests/txtar.txt
+++ b/e2etests/txtar.txt
@@ -778,7 +778,7 @@ b -> c: {
-- model-nulling --
# Models
-user
+user.style.fill: blue
softwareSystem: {
serviceA
serviceB
@@ -802,3 +802,5 @@ yes: {
ok
}
a -> b
+
+user: !null