cat / 012
clone

a spreadsheet for the terminal: lotus 1-2-3 looks, google sheets keys and formulas, one go binary

cat/module-path
012 / internal / notebook / refs.go
refs.go 1.5K
1package notebook23import "strings"45// What a pipeline reads. A code cell reads another's output as $name,6// the selection on a sheet as $selection, and a range of a sheet as7// $sheet.A1:C9 (or $sheet.Sales!A1:C9, $sheet.'Q1 data'!A1:B5). Each8// reaches nu as a variable holding a table, read from a NUON file, never9// as text spliced into the pipeline: a $sheet range is renamed to a10// variable of its own ($__sheet1) before the pipeline runs11// (Source.Command).1213// Selection is the variable that holds the selection.14const Selection = "selection"1516// sheetVar starts a range of a sheet.17const sheetVar = "$sheet."1819// SheetRef is a range of a sheet a pipeline reads, $sheet.A1:C9.20type SheetRef struct {21 // Ref is the range as written after $sheet.: "A1:C9", "Sales!A1:C9".22 Ref string23 // Var is the variable it's read as once renamed: __sheet1.24 Var string25}2627// refLen is how long the range at the start of s is: a sheet's name,28// quoted in ” if it needs to be, then ! and cells, or cells alone. A29// dot ends it, so a cell path may follow: $sheet.A1:C9.name.30func refLen(s string) int {31 i := 032 if strings.HasPrefix(s, "'") {33 for i = 1; i < len(s); i++ {34 if s[i] == '\'' {35 if i+1 < len(s) && s[i+1] == '\'' {36 i++ // '' is a quote in the name37 continue38 }39 break40 }41 }42 if i >= len(s) || i+1 >= len(s) || s[i+1] != '!' {43 return 044 }45 i += 246 }47 for i < len(s) && (isWord(s[i]) || strings.IndexByte("!:$", s[i]) >= 0) {48 i++49 }50 return i51}