Skip to content

Instantly share code, notes, and snippets.

@sdboyer
Last active January 18, 2023 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdboyer/3ad62ee2aae218d353e397844c336ffd to your computer and use it in GitHub Desktop.
Save sdboyer/3ad62ee2aae218d353e397844c336ffd to your computer and use it in GitHub Desktop.
CUE expression tree printer, currently squirreled away in grafana/cuetsy
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")
ref.n1:
[.] (string)
├── (struct)
├── "node1"
└── [ref:node1]
└── (string) @cuetsy(kind="type")
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"
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"
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