Last active
January 18, 2023 13:37
-
-
Save sdboyer/3ad62ee2aae218d353e397844c336ffd to your computer and use it in GitHub Desktop.
CUE expression tree printer, currently squirreled away in grafana/cuetsy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node1: string @cuetsy(kind="type") | |
node2: string | *int @cuetsy(kind="type") | |
node3: *"foo" | "bar" | "baz" @cuetsy(kind="enum", memberNames="Foo|Bar|Baz") | |
node4: node3 | node2 | |
node5: { | |
inner: string | |
n3: node3 | |
} @cuetsy(kind="interface") | |
// Each other file in this gist corresponds to taking a field under ref here | |
// and printing a tree of the cue.Values returned from calling Value.Expr(), | |
// recursively, and traversing references | |
ref: { | |
n1: node1 | |
n2: node2 | node3 | |
n3: node2 | node3 | *"bar" | |
n4: node4 | node5.n3 | *"foo" | |
} @cuetsy(kind="interface") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ref.n1: | |
[.] (string) | |
├── (struct) | |
├── "node1" | |
└── [ref:node1] | |
└── (string) @cuetsy(kind="type") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ref.n2: | |
[|] (int|string) | |
├── [.] (int|string) | |
│ ├── (struct) | |
│ ├── "node2" | |
│ ├── [ref:node2] | |
│ │ └── [|] (int|string) @cuetsy(kind="type") | |
│ │ ├── (string) | |
│ │ ├── (int) | |
│ │ └── [*] | |
│ │ └── (int) | |
│ └── [*] | |
│ └── [.] (int) | |
│ ├── (struct) | |
│ ├── "node2" | |
│ └── [ref:node2] | |
│ └── [|] (int|string) @cuetsy(kind="type") | |
│ ├── (string) | |
│ ├── (int) | |
│ └── [*] | |
│ └── (int) | |
├── [.] (string) | |
│ ├── (struct) | |
│ ├── "node3" | |
│ ├── [ref:node3] | |
│ │ └── [|] (string) @cuetsy(kind="enum", memberNames="Foo|Bar|Baz") | |
│ │ ├── "foo" | |
│ │ ├── "bar" | |
│ │ ├── "baz" | |
│ │ └── [*] | |
│ │ └── "foo" | |
│ └── [*] | |
│ └── [.] "foo" | |
│ ├── (struct) | |
│ ├── "node3" | |
│ └── [ref:node3] | |
│ └── [|] (string) @cuetsy(kind="enum", memberNames="Foo|Bar|Baz") | |
│ ├── "foo" | |
│ ├── "bar" | |
│ ├── "baz" | |
│ └── [*] | |
│ └── "foo" | |
└── [*] | |
└── [|] (int|string) | |
├── [.] (int|string) | |
│ ├── (struct) | |
│ ├── "node2" | |
│ ├── [ref:node2] | |
│ │ └── [|] (int|string) @cuetsy(kind="type") | |
│ │ ├── (string) | |
│ │ ├── (int) | |
│ │ └── [*] | |
│ │ └── (int) | |
│ └── [*] | |
│ └── [.] (int) | |
│ ├── (struct) | |
│ ├── "node2" | |
│ └── [ref:node2] | |
│ └── [|] (int|string) @cuetsy(kind="type") | |
│ ├── (string) | |
│ ├── (int) | |
│ └── [*] | |
│ └── (int) | |
└── [.] (string) | |
├── (struct) | |
├── "node3" | |
├── [ref:node3] | |
│ └── [|] (string) @cuetsy(kind="enum", memberNames="Foo|Bar|Baz") | |
│ ├── "foo" | |
│ ├── "bar" | |
│ ├── "baz" | |
│ └── [*] | |
│ └── "foo" | |
└── [*] | |
└── [.] "foo" | |
├── (struct) | |
├── "node3" | |
└── [ref:node3] | |
└── [|] (string) @cuetsy(kind="enum", memberNames="Foo|Bar|Baz") | |
├── "foo" | |
├── "bar" | |
├── "baz" | |
└── [*] | |
└── "foo" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ref.n3: | |
[|] (int|string) | |
├── [.] (int|string) | |
│ ├── (struct) | |
│ ├── "node2" | |
│ ├── [ref:node2] | |
│ │ └── [|] (int|string) @cuetsy(kind="type") | |
│ │ ├── (string) | |
│ │ ├── (int) | |
│ │ └── [*] | |
│ │ └── (int) | |
│ └── [*] | |
│ └── [.] (int) | |
│ ├── (struct) | |
│ ├── "node2" | |
│ └── [ref:node2] | |
│ └── [|] (int|string) @cuetsy(kind="type") | |
│ ├── (string) | |
│ ├── (int) | |
│ └── [*] | |
│ └── (int) | |
├── [.] (string) | |
│ ├── (struct) | |
│ ├── "node3" | |
│ ├── [ref:node3] | |
│ │ └── [|] (string) @cuetsy(kind="enum", memberNames="Foo|Bar|Baz") | |
│ │ ├── "foo" | |
│ │ ├── "bar" | |
│ │ ├── "baz" | |
│ │ └── [*] | |
│ │ └── "foo" | |
│ └── [*] | |
│ └── [.] "foo" | |
│ ├── (struct) | |
│ ├── "node3" | |
│ └── [ref:node3] | |
│ └── [|] (string) @cuetsy(kind="enum", memberNames="Foo|Bar|Baz") | |
│ ├── "foo" | |
│ ├── "bar" | |
│ ├── "baz" | |
│ └── [*] | |
│ └── "foo" | |
├── "bar" | |
└── [*] | |
└── "bar" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ref.bigref: | |
[|] (int|string) | |
├── [.] (int|string) | |
│ ├── (struct) | |
│ ├── "node4" | |
│ ├── [ref:node4] | |
│ │ └── [|] (int|string) | |
│ │ ├── [.] (string) | |
│ │ │ ├── (struct) | |
│ │ │ ├── "node3" | |
│ │ │ ├── [ref:node3] | |
│ │ │ │ └── [|] (string) @cuetsy(kind="enum", memberNames="Foo|Bar|Baz") | |
│ │ │ │ ├── "foo" | |
│ │ │ │ ├── "bar" | |
│ │ │ │ ├── "baz" | |
│ │ │ │ └── [*] | |
│ │ │ │ └── "foo" | |
│ │ │ └── [*] | |
│ │ │ └── [.] "foo" | |
│ │ │ ├── (struct) | |
│ │ │ ├── "node3" | |
│ │ │ └── [ref:node3] | |
│ │ │ └── [|] (string) @cuetsy(kind="enum", memberNames="Foo|Bar|Baz") | |
│ │ │ ├── "foo" | |
│ │ │ ├── "bar" | |
│ │ │ ├── "baz" | |
│ │ │ └── [*] | |
│ │ │ └── "foo" | |
│ │ ├── [.] (int|string) | |
│ │ │ ├── (struct) | |
│ │ │ ├── "node2" | |
│ │ │ ├── [ref:node2] | |
│ │ │ │ └── [|] (int|string) @cuetsy(kind="type") | |
│ │ │ │ ├── (string) | |
│ │ │ │ ├── (int) | |
│ │ │ │ └── [*] | |
│ │ │ │ └── (int) | |
│ │ │ └── [*] | |
│ │ │ └── [.] (int) | |
│ │ │ ├── (struct) | |
│ │ │ ├── "node2" | |
│ │ │ └── [ref:node2] | |
│ │ │ └── [|] (int|string) @cuetsy(kind="type") | |
│ │ │ ├── (string) | |
│ │ │ ├── (int) | |
│ │ │ └── [*] | |
│ │ │ └── (int) | |
│ │ └── [*] | |
│ │ └── [|] (int|string) | |
│ │ ├── [.] (string) | |
│ │ │ ├── (struct) | |
│ │ │ ├── "node3" | |
│ │ │ ├── [ref:node3] | |
│ │ │ │ └── [|] (string) @cuetsy(kind="enum", memberNames="Foo|Bar|Baz") | |
│ │ │ │ ├── "foo" | |
│ │ │ │ ├── "bar" | |
│ │ │ │ ├── "baz" | |
│ │ │ │ └── [*] | |
│ │ │ │ └── "foo" | |
│ │ │ └── [*] | |
│ │ │ └── [.] "foo" | |
│ │ │ ├── (struct) | |
│ │ │ ├── "node3" | |
│ │ │ └── [ref:node3] | |
│ │ │ └── [|] (string) @cuetsy(kind="enum", memberNames="Foo|Bar|Baz") | |
│ │ │ ├── "foo" | |
│ │ │ ├── "bar" | |
│ │ │ ├── "baz" | |
│ │ │ └── [*] | |
│ │ │ └── "foo" | |
│ │ └── [.] (int|string) | |
│ │ ├── (struct) | |
│ │ ├── "node2" | |
│ │ ├── [ref:node2] | |
│ │ │ └── [|] (int|string) @cuetsy(kind="type") | |
│ │ │ ├── (string) | |
│ │ │ ├── (int) | |
│ │ │ └── [*] | |
│ │ │ └── (int) | |
│ │ └── [*] | |
│ │ └── [.] (int) | |
│ │ ├── (struct) | |
│ │ ├── "node2" | |
│ │ └── [ref:node2] | |
│ │ └── [|] (int|string) @cuetsy(kind="type") | |
│ │ ├── (string) | |
│ │ ├── (int) | |
│ │ └── [*] | |
│ │ └── (int) | |
│ └── [*] | |
│ └── [.] (int|string) | |
│ ├── (struct) | |
│ ├── "node4" | |
│ └── [ref:node4] | |
│ └── [|] (int|string) | |
│ ├── [.] (string) | |
│ │ ├── (struct) | |
│ │ ├── "node3" | |
│ │ ├── [ref:node3] | |
│ │ │ └── [|] (string) @cuetsy(kind="enum", memberNames="Foo|Bar|Baz") | |
│ │ │ ├── "foo" | |
│ │ │ ├── "bar" | |
│ │ │ ├── "baz" | |
│ │ │ └── [*] | |
│ │ │ └── "foo" | |
│ │ └── [*] | |
│ │ └── [.] "foo" | |
│ │ ├── (struct) | |
│ │ ├── "node3" | |
│ │ └── [ref:node3] | |
│ │ └── [|] (string) @cuetsy(kind="enum", memberNames="Foo|Bar|Baz") | |
│ │ ├── "foo" | |
│ │ ├── "bar" | |
│ │ ├── "baz" | |
│ │ └── [*] | |
│ │ └── "foo" | |
│ ├── [.] (int|string) | |
│ │ ├── (struct) | |
│ │ ├── "node2" | |
│ │ ├── [ref:node2] | |
│ │ │ └── [|] (int|string) @cuetsy(kind="type") | |
│ │ │ ├── (string) | |
│ │ │ ├── (int) | |
│ │ │ └── [*] | |
│ │ │ └── (int) | |
│ │ └── [*] | |
│ │ └── [.] (int) | |
│ │ ├── (struct) | |
│ │ ├── "node2" | |
│ │ └── [ref:node2] | |
│ │ └── [|] (int|string) @cuetsy(kind="type") | |
│ │ ├── (string) | |
│ │ ├── (int) | |
│ │ └── [*] | |
│ │ └── (int) | |
│ └── [*] | |
│ └── [|] (int|string) | |
│ ├── [.] (string) | |
│ │ ├── (struct) | |
│ │ ├── "node3" | |
│ │ ├── [ref:node3] | |
│ │ │ └── [|] (string) @cuetsy(kind="enum", memberNames="Foo|Bar|Baz") | |
│ │ │ ├── "foo" | |
│ │ │ ├── "bar" | |
│ │ │ ├── "baz" | |
│ │ │ └── [*] | |
│ │ │ └── "foo" | |
│ │ └── [*] | |
│ │ └── [.] "foo" | |
│ │ ├── (struct) | |
│ │ ├── "node3" | |
│ │ └── [ref:node3] | |
│ │ └── [|] (string) @cuetsy(kind="enum", memberNames="Foo|Bar|Baz") | |
│ │ ├── "foo" | |
│ │ ├── "bar" | |
│ │ ├── "baz" | |
│ │ └── [*] | |
│ │ └── "foo" | |
│ └── [.] (int|string) | |
│ ├── (struct) | |
│ ├── "node2" | |
│ ├── [ref:node2] | |
│ │ └── [|] (int|string) @cuetsy(kind="type") | |
│ │ ├── (string) | |
│ │ ├── (int) | |
│ │ └── [*] | |
│ │ └── (int) | |
│ └── [*] | |
│ └── [.] (int) | |
│ ├── (struct) | |
│ ├── "node2" | |
│ └── [ref:node2] | |
│ └── [|] (int|string) @cuetsy(kind="type") | |
│ ├── (string) | |
│ ├── (int) | |
│ └── [*] | |
│ └── (int) | |
├── [.] (string) | |
│ ├── [.] (struct) | |
│ │ ├── (struct) | |
│ │ ├── "node5" | |
│ │ └── [ref:node5] | |
│ │ └── (struct) @cuetsy(kind="interface") | |
│ ├── "n3" | |
│ ├── [ref:node5.n3] | |
│ │ └── [.] (string) | |
│ │ ├── (struct) | |
│ │ ├── "node3" | |
│ │ ├── [ref:node3] | |
│ │ │ └── [|] (string) @cuetsy(kind="enum", memberNames="Foo|Bar|Baz") | |
│ │ │ ├── "foo" | |
│ │ │ ├── "bar" | |
│ │ │ ├── "baz" | |
│ │ │ └── [*] | |
│ │ │ └── "foo" | |
│ │ └── [*] | |
│ │ └── [.] "foo" | |
│ │ ├── (struct) | |
│ │ ├── "node3" | |
│ │ └── [ref:node3] | |
│ │ └── [|] (string) @cuetsy(kind="enum", memberNames="Foo|Bar|Baz") | |
│ │ ├── "foo" | |
│ │ ├── "bar" | |
│ │ ├── "baz" | |
│ │ └── [*] | |
│ │ └── "foo" | |
│ └── [*] | |
│ └── [.] "foo" | |
│ ├── [.] (struct) | |
│ │ ├── (struct) | |
│ │ ├── "node5" | |
│ │ └── [ref:node5] | |
│ │ └── (struct) @cuetsy(kind="interface") | |
│ ├── "n3" | |
│ └── [ref:node5.n3] | |
│ └── [.] (string) | |
│ ├── (struct) | |
│ ├── "node3" | |
│ ├── [ref:node3] | |
│ │ └── [|] (string) @cuetsy(kind="enum", memberNames="Foo|Bar|Baz") | |
│ │ ├── "foo" | |
│ │ ├── "bar" | |
│ │ ├── "baz" | |
│ │ └── [*] | |
│ │ └── "foo" | |
│ └── [*] | |
│ └── [.] "foo" | |
│ ├── (struct) | |
│ ├── "node3" | |
│ └── [ref:node3] | |
│ └── [|] (string) @cuetsy(kind="enum", memberNames="Foo|Bar|Baz") | |
│ ├── "foo" | |
│ ├── "bar" | |
│ ├── "baz" | |
│ └── [*] | |
│ └── "foo" | |
└── [*] | |
└── "foo" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment