zc

package
v5.12.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AnnotationMarker = "#!(anno)"
	AnnotationSep    = "#"
)
View Source
const (
	Version   = "v5.12.4"
	BuildDate = "16 Mar 2024"
)
View Source
const ProgName = "zc"

Variables

View Source
var (
	BigFloat = BigFloatType{Precision: 53, RoundingMode: big.ToNearestEven}
	BigInt   = BigIntType{}
	Bool     = BoolType{}
	Char     = CharType{}
	Complex  = ComplexType{}
	Date     = DateType{}
	DateTime = DateTimeType{}
	Decimal  = DecimalType{}
	DMS      = DMSType{}
	Duration = DurationType{}
	Float    = FloatType{}
	Int      = IntType{}
	Int64    = Int64Type{}
	Int32    = Int32Type{}
	Rational = RationalType{}
	Str      = StrType{}
	Time     = TimeType{}
	Uint     = UintType{}
	Uint8    = Uint8Type{}
	Val      = StrType{}
)
View Source
var Now = func() time.Time { return time.Now() }

Functions

func Annotate

func Annotate(c Calc, format string, a ...any)

func Clamp

func Clamp[T constraints.Ordered](v T, min T, max T) T

func ErrDivisionByZero

func ErrDivisionByZero(c Calc)

func ErrExpectedType

func ErrExpectedType(c Calc, t Type, val string)

func ErrFeatureNotSupported

func ErrFeatureNotSupported(name string) error

func ErrInfinity

func ErrInfinity(c Calc, sign int)

func ErrInvalidArgs

func ErrInvalidArgs(c Calc, reason string)

func ErrInvalidFunc

func ErrInvalidFunc(c Calc, fn string, reason string)

func ErrNoOpFor

func ErrNoOpFor(c Calc, name string, args []string)

func ErrNotANumber

func ErrNotANumber(c Calc)

func ErrNotEnoughArgs

func ErrNotEnoughArgs(c Calc, op string, expected int)

func ErrUnknownOp

func ErrUnknownOp(name string) error

func Format

func Format(a any) string

func FormatStackItem

func FormatStackItem(v string) string

func IsValuePrefix

func IsValuePrefix(ch rune, next rune) bool

func NoOp

func NoOp(c Calc)

func PanicExpectedType

func PanicExpectedType(t Type, val string)

func PopBigFloat

func PopBigFloat(c Calc) *big.Float

func PopBigInt

func PopBigInt(c Calc) *big.Int

func PopBool

func PopBool(c Calc) bool

func PopComplex

func PopComplex(c Calc) complex128

func PopDMS

func PopDMS(c Calc) types.DMS

func PopDate

func PopDate(c Calc) time.Time

func PopDateTime

func PopDateTime(c Calc) time.Time

func PopDecimal

func PopDecimal(c Calc) types.Decimal

func PopDuration

func PopDuration(c Calc) time.Duration

func PopFloat

func PopFloat(c Calc) float64

func PopInt

func PopInt(c Calc) int

func PopInt32

func PopInt32(c Calc) int32

func PopInt64

func PopInt64(c Calc) int64

func PopRational

func PopRational(c Calc) *big.Rat

func PopRune

func PopRune(c Calc) rune

func PopString

func PopString(c Calc) string

func PopTime

func PopTime(c Calc) time.Time

func PopUint

func PopUint(c Calc) uint

func PopUint8

func PopUint8(c Calc) uint8

func PostFormatFloat

func PostFormatFloat(str string) string

func PreParseFloat

func PreParseFloat(s string, suffix string) string

func PushBigFloat

func PushBigFloat(c Calc, r *big.Float)

func PushBigInt

func PushBigInt(c Calc, r *big.Int)

func PushBool

func PushBool(c Calc, r bool)

func PushComplex

func PushComplex(c Calc, r complex128)

func PushDMS

func PushDMS(c Calc, r types.DMS)

func PushDate

func PushDate(c Calc, r time.Time)

func PushDateTime

func PushDateTime(c Calc, r time.Time)

func PushDecimal

func PushDecimal(c Calc, r types.Decimal)

func PushDuration

func PushDuration(c Calc, r time.Duration)

func PushFloat

func PushFloat(c Calc, r float64)

func PushInt

func PushInt(c Calc, r int)

func PushInt32

func PushInt32(c Calc, r int32)

func PushInt64

func PushInt64(c Calc, r int64)

func PushRational

func PushRational(c Calc, r *big.Rat)

func PushRune

func PushRune(c Calc, r rune)

func PushString

func PushString(c Calc, r string)

func PushTime

func PushTime(c Calc, r time.Time)

func PushUint

func PushUint(c Calc, r uint)

func PushUint8

func PushUint8(c Calc, r uint8)

func Quote

func Quote(v string) string

func RemoveAnnotation

func RemoveAnnotation(v string) string

func StackString

func StackString(c Calc) string

Types

type BigFloatType

type BigFloatType struct {
	Precision    uint
	RoundingMode big.RoundingMode
}

func (BigFloatType) Compare

func (t BigFloatType) Compare(x1 string, x2 string) (int, bool)

func (BigFloatType) Format

func (t BigFloatType) Format(v *big.Float) string

func (BigFloatType) Is

func (t BigFloatType) Is(s string) bool

func (BigFloatType) MustParse

func (t BigFloatType) MustParse(s string) *big.Float

func (BigFloatType) Parse

func (t BigFloatType) Parse(s string) (*big.Float, bool)

func (BigFloatType) String

func (t BigFloatType) String() string

type BigIntType

type BigIntType struct{}

func (BigIntType) Compare

func (t BigIntType) Compare(x1 string, x2 string) (int, bool)

func (BigIntType) Format

func (t BigIntType) Format(v *big.Int) string

func (BigIntType) Is

func (t BigIntType) Is(s string) bool

func (BigIntType) MustParse

func (t BigIntType) MustParse(s string) *big.Int

func (BigIntType) Parse

func (t BigIntType) Parse(s string) (*big.Int, bool)

func (BigIntType) String

func (t BigIntType) String() string

type BoolType

type BoolType struct{}

func (BoolType) Format

func (t BoolType) Format(v bool) string

func (BoolType) Is

func (t BoolType) Is(s string) bool

func (BoolType) MustParse

func (t BoolType) MustParse(s string) bool

func (BoolType) Parse

func (t BoolType) Parse(s string) (bool, bool)

func (BoolType) String

func (t BoolType) String() string

type Calc

type Calc interface {
	Eval(string, ...any) error
	MustEval(string, ...any)
	Stack() []string
	StackLen() int
	SetStack([]string)
	Peek(int) (string, bool)
	Pop() (string, bool)
	MustPop() string
	TopAnnotation() string
	Push(string)
	Info() string
	SetInfo(string, ...any)
	Error() error
	SetError(error)
	Derive() Calc
	NewState(string, any)
	State(string) (any, bool)
	SetOp(string)
	SetArgs([]string)
	Op() OpCall
	OpNames() []string
}

type CalcFunc

type CalcFunc func(Calc)

type CharType

type CharType struct{}

func (CharType) Format

func (t CharType) Format(v rune) string

func (CharType) Is

func (t CharType) Is(s string) bool

func (CharType) MustParse

func (t CharType) MustParse(s string) rune

func (CharType) Parse

func (t CharType) Parse(s string) (rune, bool)

func (CharType) String

func (t CharType) String() string

type ComplexType

type ComplexType struct{}

func (ComplexType) Format

func (t ComplexType) Format(v complex128) string

func (ComplexType) Is

func (t ComplexType) Is(s string) bool

func (ComplexType) MustParse

func (t ComplexType) MustParse(s string) complex128

func (ComplexType) Parse

func (t ComplexType) Parse(s string) (complex128, bool)

func (ComplexType) String

func (t ComplexType) String() string

type DMSType

type DMSType struct{}

func (DMSType) Format

func (t DMSType) Format(v types.DMS) string

func (DMSType) Is

func (t DMSType) Is(s string) bool

func (DMSType) MustParse

func (t DMSType) MustParse(s string) types.DMS

func (DMSType) Parse

func (t DMSType) Parse(str string) (types.DMS, bool)

func (DMSType) String

func (t DMSType) String() string

type DateTimeType

type DateTimeType struct{}

func (DateTimeType) Compare

func (t DateTimeType) Compare(x1 string, x2 string) (int, bool)

func (DateTimeType) Format

func (t DateTimeType) Format(tm time.Time) string

func (DateTimeType) Is

func (t DateTimeType) Is(s string) bool

func (DateTimeType) MustParse

func (t DateTimeType) MustParse(s string) time.Time

func (DateTimeType) Parse

func (t DateTimeType) Parse(str string) (time.Time, bool)

func (DateTimeType) String

func (t DateTimeType) String() string

type DateType

type DateType struct{}

func (DateType) Compare

func (t DateType) Compare(x1 string, x2 string) (int, bool)

func (DateType) Format

func (t DateType) Format(tm time.Time) string

func (DateType) Is

func (t DateType) Is(s string) bool

func (DateType) MustParse

func (t DateType) MustParse(s string) time.Time

func (DateType) Parse

func (t DateType) Parse(s string) (time.Time, bool)

func (DateType) String

func (t DateType) String() string

type DecimalType

type DecimalType struct{}

func (DecimalType) Compare

func (t DecimalType) Compare(x1 string, x2 string) (int, bool)

func (DecimalType) Format

func (t DecimalType) Format(v types.Decimal) string

func (DecimalType) Is

func (t DecimalType) Is(s string) bool

func (DecimalType) MustParse

func (t DecimalType) MustParse(s string) types.Decimal

func (DecimalType) Parse

func (t DecimalType) Parse(s string) (types.Decimal, bool)

func (DecimalType) String

func (t DecimalType) String() string

type DurationType

type DurationType struct{}

func (DurationType) Compare

func (t DurationType) Compare(x1 string, x2 string) (int, bool)

func (DurationType) Format

func (t DurationType) Format(v time.Duration) string

func (DurationType) Is

func (t DurationType) Is(s string) bool

func (DurationType) MustParse

func (t DurationType) MustParse(s string) time.Duration

func (DurationType) Parse

func (t DurationType) Parse(str string) (time.Duration, bool)

func (DurationType) String

func (t DurationType) String() string

type FloatType

type FloatType struct{}

func (FloatType) Compare

func (t FloatType) Compare(x1 string, x2 string) (int, bool)

func (FloatType) Format

func (t FloatType) Format(v float64) string

func (FloatType) Is

func (t FloatType) Is(s string) bool

func (FloatType) MustParse

func (t FloatType) MustParse(s string) float64

func (FloatType) Parse

func (t FloatType) Parse(s string) (float64, bool)

func (FloatType) String

func (t FloatType) String() string

type FuncDecl

type FuncDecl struct {
	Func   CalcFunc
	Params []Type
}

func Func

func Func(fn CalcFunc, params ...Type) FuncDecl

type Int32Type

type Int32Type struct{}

func (Int32Type) Compare

func (t Int32Type) Compare(x1 string, x2 string) (int, bool)

func (Int32Type) Format

func (t Int32Type) Format(v int32) string

func (Int32Type) Is

func (t Int32Type) Is(s string) bool

func (Int32Type) MustParse

func (t Int32Type) MustParse(s string) int32

func (Int32Type) Parse

func (t Int32Type) Parse(s string) (int32, bool)

func (Int32Type) String

func (t Int32Type) String() string

type Int64Type

type Int64Type struct{}

func (Int64Type) Compare

func (t Int64Type) Compare(x1 string, x2 string) (int, bool)

func (Int64Type) Format

func (t Int64Type) Format(v int64) string

func (Int64Type) Is

func (t Int64Type) Is(s string) bool

func (Int64Type) MustParse

func (t Int64Type) MustParse(s string) int64

func (Int64Type) Parse

func (t Int64Type) Parse(s string) (int64, bool)

func (Int64Type) String

func (t Int64Type) String() string

type IntType

type IntType struct{}

func (IntType) Compare

func (t IntType) Compare(x1 string, x2 string) (int, bool)

func (IntType) Format

func (t IntType) Format(v int) string

func (IntType) Is

func (t IntType) Is(s string) bool

func (IntType) MustParse

func (t IntType) MustParse(s string) int

func (IntType) Parse

func (t IntType) Parse(s string) (int, bool)

func (IntType) String

func (t IntType) String() string

type OpCall

type OpCall struct {
	Name string
	Args []string
}

func (OpCall) String

func (c OpCall) String() string

type OpDecl

type OpDecl struct {
	Name  string
	Macro string
	Funcs []FuncDecl
}

func GenOp

func GenOp(name string, funcs ...FuncDecl) OpDecl

func Macro

func Macro(name string, expr string) OpDecl

func Op

func Op(name string, fn CalcFunc, param ...Type) OpDecl

type RationalType

type RationalType struct{}

func (RationalType) Compare

func (t RationalType) Compare(x1 string, x2 string) (int, bool)

func (RationalType) Format

func (t RationalType) Format(v *big.Rat) string

func (RationalType) Is

func (t RationalType) Is(s string) bool

func (RationalType) MustParse

func (t RationalType) MustParse(s string) *big.Rat

func (RationalType) Parse

func (t RationalType) Parse(s string) (*big.Rat, bool)

func (RationalType) String

func (t RationalType) String() string

type SortInterface

type SortInterface []string

func (SortInterface) Len

func (s SortInterface) Len() int

func (SortInterface) Less

func (s SortInterface) Less(i, j int) bool

func (SortInterface) Swap

func (s SortInterface) Swap(i, j int)

type StrType

type StrType struct{}

func (StrType) Compare

func (t StrType) Compare(x1 string, x2 string) (int, bool)

func (StrType) Format

func (t StrType) Format(v string) string

func (StrType) Is

func (t StrType) Is(s string) bool

func (StrType) MustParse

func (t StrType) MustParse(s string) string

func (StrType) Parse

func (t StrType) Parse(s string) (string, bool)

func (StrType) String

func (t StrType) String() string

type TimeType

type TimeType struct{}

func (TimeType) Compare

func (t TimeType) Compare(x1 string, x2 string) (int, bool)

func (TimeType) Format

func (t TimeType) Format(tm time.Time) string

func (TimeType) Is

func (t TimeType) Is(s string) bool

func (TimeType) MustParse

func (t TimeType) MustParse(s string) time.Time

func (TimeType) Parse

func (t TimeType) Parse(s string) (time.Time, bool)

func (TimeType) String

func (t TimeType) String() string

type Type

type Type interface {
	String() string
	Is(string) bool
}

type Uint8Type

type Uint8Type struct{}

func (Uint8Type) Compare

func (t Uint8Type) Compare(x1 string, x2 string) (int, bool)

func (Uint8Type) Format

func (t Uint8Type) Format(v uint8) string

func (Uint8Type) Is

func (t Uint8Type) Is(s string) bool

func (Uint8Type) MustParse

func (t Uint8Type) MustParse(s string) uint8

func (Uint8Type) Parse

func (t Uint8Type) Parse(s string) (uint8, bool)

func (Uint8Type) String

func (t Uint8Type) String() string

type UintType

type UintType struct{}

func (UintType) Compare

func (t UintType) Compare(x1 string, x2 string) (int, bool)

func (UintType) Format

func (t UintType) Format(v uint) string

func (UintType) Is

func (t UintType) Is(s string) bool

func (UintType) MustParse

func (t UintType) MustParse(s string) uint

func (UintType) Parse

func (t UintType) Parse(s string) (uint, bool)

func (UintType) String

func (t UintType) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL