MCPcopy Create free account
hub / github.com/brimdata/super / formatType

Function formatType

sup/formatter.go:740–814  ·  view source on GitHub ↗
(b *strings.Builder, typedefs map[string]*super.TypeNamed, typ super.Type, isComponentType bool)

Source from the content-addressed store, hash-verified

738}
739
740func formatType(b *strings.Builder, typedefs map[string]*super.TypeNamed, typ super.Type, isComponentType bool) {
741 switch t := typ.(type) {
742 case *super.TypeNamed:
743 name := t.Name
744 b.WriteString(QuotedTypeName(name))
745 if typedefs[t.Name] != t {
746 b.WriteByte('=')
747 formatType(b, typedefs, t.Type, false)
748 // Don't set typedef until after children are recursively
749 // traversed so that we adhere to the DFS order of
750 // type bindings.
751 typedefs[name] = t
752 }
753 case *super.TypeRecord:
754 b.WriteByte('{')
755 for k, f := range t.Fields {
756 if k > 0 {
757 b.WriteByte(',')
758 }
759 b.WriteString(QuotedName(f.Name))
760 if f.Opt {
761 b.WriteString("?")
762 }
763 b.WriteString(":")
764 formatType(b, typedefs, f.Type, false)
765 }
766 b.WriteByte('}')
767 case *super.TypeArray:
768 b.WriteByte('[')
769 formatType(b, typedefs, t.Type, false)
770 b.WriteByte(']')
771 case *super.TypeSet:
772 b.WriteString("|[")
773 formatType(b, typedefs, t.Type, false)
774 b.WriteString("]|")
775 case *super.TypeMap:
776 b.WriteString("|{")
777 formatType(b, typedefs, t.KeyType, false)
778 b.WriteByte(':')
779 formatType(b, typedefs, t.ValType, false)
780 b.WriteString("}|")
781 case *super.TypeUnion:
782 if isComponentType {
783 b.WriteByte('(')
784 }
785 for k, typ := range t.Types {
786 if k > 0 {
787 b.WriteByte('|')
788 }
789 formatType(b, typedefs, typ, true)
790 }
791 if isComponentType {
792 b.WriteByte(')')
793 }
794 case *super.TypeEnum:
795 b.WriteString("enum(")
796 for k, s := range t.Symbols {
797 if k > 0 {

Callers 2

formatTypeBodyMethod · 0.85
FormatTypeFunction · 0.85

Calls 3

PrimitiveNameFunction · 0.92
QuotedTypeNameFunction · 0.85
QuotedNameFunction · 0.85

Tested by

no test coverage detected