From 00394a80501960ad26787b5c44435ed5ed67ad84 Mon Sep 17 00:00:00 2001 From: Alexander Neonxp Kiryukhin Date: Mon, 9 Mar 2026 23:05:42 +0300 Subject: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=BD=D0=BE=D1=81=D1=82=D1=8C=D1=8E?= =?UTF-8?q?=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BF=D0=B8=D1=81=D0=B0=D0=BB=20?= =?UTF-8?q?=D0=B1=D0=B8=D0=B1=D0=BB=D0=B8=D0=BE=D1=82=D0=B5=D0=BA=D1=83.?= =?UTF-8?q?=20=D0=9F=D0=B5=D1=80=D0=B5=D0=B2=D1=91=D0=BB=20=D1=81=20EBNF?= =?UTF-8?q?=20=D0=BD=D0=B0=20PEG.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/value.go | 85 ---------------------------------------------------------- 1 file changed, 85 deletions(-) delete mode 100644 model/value.go (limited to 'model/value.go') diff --git a/model/value.go b/model/value.go deleted file mode 100644 index 9fa8e9b..0000000 --- a/model/value.go +++ /dev/null @@ -1,85 +0,0 @@ -package model - -import ( - "fmt" - "strconv" - "strings" -) - -type Value any - -type Values []Value - -// BuildString собирает из значений Value цельную строку, при этом приводя все -// значения к типу string. Так же принимает функции типа WordLookup, которые -// последовательно будут пытаться привести значения типа Word к -// контекстозависимым значениям. Например, пытаться находить по имени переменную -// окружения ОС. -func (v Values) BuildString(lookups ...WordLookup) string { - sw := strings.Builder{} - - for _, v := range v { - switch v := v.(type) { - case string: - sw.WriteString(v) - case float64: - sw.WriteString(strconv.FormatFloat(v, 'f', 5, 64)) - case int: - sw.WriteString(strconv.Itoa(v)) - case bool: - if v { - sw.WriteString("true") - continue - } - sw.WriteString("false") - case Word: - sw.WriteString(chainLookup(lookups...)(v)) - } - } - - return sw.String() -} - -func (v Values) String() string { - result := make([]string, 0, len(v)) - - for _, v := range v { - switch v := v.(type) { - case string: - result = append(result, v) - case float64: - result = append(result, strconv.FormatFloat(v, 'f', 5, 64)) - case int: - result = append(result, strconv.Itoa(v)) - case bool: - if v { - result = append(result, "true") - continue - } - result = append(result, "false") - case Word: - result = append(result, string(v)) - } - } - - return strings.Join(result, " ") -} - -func (v Values) Int() (int, error) { - if len(v) != 1 { - return 0, fmt.Errorf("AsInt can return only single value (there is %d values)", len(v)) - } - val := v[0] - switch val := val.(type) { - case int: - return val, nil - case string: - return strconv.Atoi(val) - case float64: - return int(val), nil - default: - return 0, fmt.Errorf("invalid type for convert to int: %t", val) - } -} - -type Word string -- cgit v1.2.3