From c93bef6433ebf7918cd0ccfde2e8174cbdbab195 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rok=20Su=C5=A1nik?= Date: Tue, 5 Nov 2024 16:18:23 +0100 Subject: [PATCH] implement spreadsheet dump --- .gitignore | 1 + env/spreadsheet.go | 30 ++++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 039fd814..a3a0a63d 100644 --- a/.gitignore +++ b/.gitignore @@ -43,6 +43,7 @@ dist/ tests/*.html shell_*.rye console_*.rye +console_*.rye.enc buildtemp/main.rye *.bson diff --git a/env/spreadsheet.go b/env/spreadsheet.go index ac42ba99..b3534ed2 100644 --- a/env/spreadsheet.go +++ b/env/spreadsheet.go @@ -312,8 +312,34 @@ func (s Spreadsheet) Equal(o Object) bool { } func (s Spreadsheet) Dump(e Idxs) string { - // TODO - return fmt.Sprintf("\"serlization of %s is not yet supported\" ", s.Inspect(e)) + var sb strings.Builder + sb.WriteString("spreadsheet {") + + for _, col := range s.Cols { + sb.WriteString(" ") + sb.WriteString("\"") + sb.WriteString(col) + sb.WriteString("\"") + } + sb.WriteString(" } [") + + for _, row := range s.Rows { + for _, val := range row.Values { + sb.WriteString(" ") + ryeVal := ToRyeValue(val) + if ryeVal != nil { + sb.WriteString(ryeVal.Dump(e)) + } else { + sb.WriteString("_") + } + } + // Fill in missing columns (if they exist) with void (_) + for i := len(row.Values); i < len(s.Cols); i++ { + sb.WriteString(" _") + } + } + sb.WriteString(" ]") + return sb.String() } func (s SpreadsheetRow) GetKind() int {