1package sheet23import (4 "src.rest/cat/012/internal/formula"5 "src.rest/cat/012/internal/functions"6)78// The formula language lives in internal/formula. The engine's API keeps9// its names for addresses, ranges and parsing, so callers see one package.1011type (12 // Addr identifies a cell by zero-based column and row.13 Addr = formula.Addr14 // Rect is an inclusive rectangular range of cells.15 Rect = formula.Rect16 // Node is a parsed formula expression.17 Node = formula.Node18 // ParseError describes a formula that could not be parsed.19 ParseError = formula.ParseError20)2122// Worksheet bounds, matching Lotus 1-2-3 Release 2 (A..IV, 1..8192).23const (24 MaxCols = formula.MaxCols25 MaxRows = formula.MaxRows26)2728// ColName converts a zero-based column index to letters: 0 -> A, 26 -> AA.29func ColName(c int) string { return formula.ColName(c) }3031// ParseCol converts column letters (case-insensitive) to a zero-based index.32func ParseCol(s string) (int, bool) { return formula.ParseCol(s) }3334// ParseAddr parses an A1-style reference, ignoring absolute markers.35func ParseAddr(s string) (Addr, bool) { return formula.ParseAddr(s) }3637// NewRect returns the normalized rectangle spanning a and b.38func NewRect(a, b Addr) Rect { return formula.NewRect(a, b) }3940// ParseRange parses "A1", "A1:B3" or 1-2-3 style "A1..B3".41func ParseRange(s string) (Rect, bool) { return formula.ParseRange(s) }4243// QuoteSheet writes a sheet name as a formula needs it, e.g. 'Q3 plan'.44func QuoteSheet(name string) string { return formula.QuoteSheet(name) }4546// SplitSheet splits a reference such as "'Q3 plan'!B2" into the sheet47// name, unquoted, and the rest.48func SplitSheet(s string) (sheet, rest string) { return formula.SplitSheet(s) }4950// Qualified writes r on sheet as a formula would: Sheet2!A1:B3.51func Qualified(sheet string, r Rect) string { return formula.Qualified(sheet, r) }5253// EscapeColumn writes a table column's name as a structured reference54// holds it, with ' before each of [ ] # and '.55func EscapeColumn(name string) string { return formula.EscapeColumn(name) }5657// Parse parses a formula with this engine's functions. src may start58// with "="; error positions are relative to src.59func Parse(src string) (Node, error) { return formula.Parse(src, parserFuncs) }6061// parserFuncs is the function table as the parser sees it.62func parserFuncs(name string) (formula.Func, bool) {63 if f, ok := LookupFunc(name); ok {64 return f, true65 }66 return nil, false67}6869// funcOf is the function a parsed call calls: always one of the70// library's, since the parser only finds functions through parserFuncs.71func funcOf(c formula.Call) *FuncDef { return functions.Of(c) }7273func isLetter(c byte) bool {74 return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')75}7677func isDigit(c byte) bool {78 return c >= '0' && c <= '9'79}