1package types 2 3import ( 4 "fmt" 5 "os" 6 "strconv" 7) 8 9// See mlrval.go for more about JIT-formatting of string backings 10func (this *Mlrval) setPrintRep() { 11 if !this.printrepValid { 12 // xxx do it -- disposition vector 13 // xxx temp temp temp temp temp 14 switch this.mvtype { 15 case MT_PENDING: 16 // Should not have gotten outside of the JSON decoder, so flag this 17 // clearly visually if it should (buggily) slip through to 18 // user-level visibility. 19 this.printrep = "(bug-if-you-see-this)" // xxx constdef at top of file 20 break 21 case MT_ERROR: 22 this.printrep = "(error)" // xxx constdef at top of file 23 break 24 case MT_ABSENT: 25 // Callsites should be using absence to do non-assigns, so flag 26 // this clearly visually if it should (buggily) slip through to 27 // user-level visibility. 28 this.printrep = "(bug-if-you-see-this)" // xxx constdef at top of file 29 break 30 case MT_VOID: 31 this.printrep = "" // xxx constdef at top of file 32 break 33 case MT_STRING: 34 // panic i suppose 35 break 36 case MT_INT: 37 this.printrep = strconv.Itoa(this.intval) 38 break 39 case MT_FLOAT: 40 // xxx temp -- OFMT etc ... 41 this.printrep = strconv.FormatFloat(this.floatval, 'g', -1, 64) 42 break 43 case MT_BOOL: 44 if this.boolval == true { 45 this.printrep = "true" 46 } else { 47 this.printrep = "false" 48 } 49 break 50 // TODO: handling indentation 51 case MT_ARRAY: 52 53 bytes, err := this.MarshalJSON(JSON_MULTILINE) 54 // maybe just InternalCodingErrorIf(err != nil) 55 if err != nil { 56 fmt.Fprintln(os.Stderr, err) 57 os.Exit(1) 58 } 59 this.printrep = string(bytes) 60 61 break 62 case MT_MAP: 63 64 bytes, err := this.MarshalJSON(JSON_MULTILINE) 65 // maybe just InternalCodingErrorIf(err != nil) 66 if err != nil { 67 fmt.Fprintln(os.Stderr, err) 68 os.Exit(1) 69 } 70 this.printrep = string(bytes) 71 72 break 73 } 74 this.printrepValid = true 75 } 76} 77 78// Must have non-pointer receiver in order to implement the fmt.Stringer 79// interface to make this printable via fmt.Println et al. 80func (this Mlrval) String() string { 81 this.setPrintRep() 82 return this.printrep 83} 84