package valsimport ()// NoPretty can be passed to Repr to suppress pretty-printing.constNoPretty = math.MinInt32// Reprer wraps the Repr method.typeReprerinterface {// Repr returns a string that represents a Value. The string either be a // literal of that Value that is preferably deep-equal to it (like `[a b c]` // for a list), or a string enclosed in "<>" containing the kind and // identity of the Value(like `<fn 0xdeadcafe>`). // // If indent is at least 0, it should be pretty-printed with the current // indentation level of indent; the indent of the first line has already // been written and shall not be written in Repr. The returned string // should never contain a trailing newline.Repr(indent int) string}// Repr returns the representation for a value, a string that is preferably (but// not necessarily) an Elvish expression that evaluates to the argument. If// indent >= 0, the representation is pretty-printed. It is implemented for the// builtin types nil, bool and string, the File, List and Map types, StructMap// types, and types satisfying the Reprer interface. For other types, it uses// fmt.Sprint with the format "<unknown %v>".func ( interface{}, int) string {switch v := .(type) {casenil:return"$nil"casebool:if {return"$true" }return"$false"casestring:returnparse.Quote()caseint:return"(num " + strconv.Itoa() + ")"case *big.Int:return"(num " + .String() + ")"case *big.Rat:return"(num " + .String() + ")"casefloat64:return"(num " + formatFloat64() + ")"caseReprer:return .Repr()caseFile:returnfmt.Sprintf("<file{%s %d}>", parse.Quote(.Name()), .Fd())caseList: := NewListReprBuilder()for := .Iterator(); .HasElem(); .Next() { .WriteElem((.Elem(), +1)) }return .String()caseMap: := NewMapReprBuilder()for := .Iterator(); .HasElem(); .Next() { , := .Elem() .WritePair((, +1), +2, (, +2)) }return .String()caseStructMap:returnreprStructMap(, )casePseudoStructMap:returnreprStructMap(.Fields(), )default:returnfmt.Sprintf("<unknown %v>", ) }}func ( StructMap, int) string { := reflect.ValueOf() := .Type() := NewMapReprBuilder() := iterateStructMap()for .Next() { , := .Get() .WritePair(Repr(, +1), +2, Repr(, +2)) }return .String()}
The pages are generated with Goldsv0.2.8-preview. (GOOS=darwin GOARCH=arm64)