interp

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2024 License: MIT Imports: 43 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultRegistry = NewRegistry()

DefaultRegistry global registry used by formats

View Source
var ErrEOF = io.EOF
View Source
var ErrInterrupt = errors.New("Interrupt")
View Source
var PlainDecorator = Decorator{
	Column:     "|",
	ValueColor: func(v any) ansi.Code { return ansi.None },
	ByteColor:  func(b byte) ansi.Code { return ansi.None },
}

Functions

func RegisterFS added in v0.0.8

func RegisterFS(fs fs.ReadDirFS)

func RegisterFormat added in v0.0.8

func RegisterFormat(group *decode.Group, format *decode.Format)

func RegisterFunc0 added in v0.0.8

func RegisterFunc0[Tc any](name string, fn func(e *Interp, c Tc) any)

func RegisterFunc1 added in v0.0.8

func RegisterFunc1[Tc any, Ta0 any](name string, fn func(e *Interp, c Tc, a0 Ta0) any)

func RegisterFunc2 added in v0.0.8

func RegisterFunc2[Tc any, Ta0 any, Ta1 any](name string, fn func(e *Interp, c Tc, a0 Ta0, a1 Ta1) any)

func RegisterIter0 added in v0.0.8

func RegisterIter0[Tc any](name string, fn func(e *Interp, c Tc) gojq.Iter)

func RegisterIter1 added in v0.0.8

func RegisterIter1[Tc any, Ta0 any](name string, fn func(e *Interp, c Tc, a0 Ta0) gojq.Iter)

func RegisterIter2 added in v0.0.8

func RegisterIter2[Tc any, Ta0 any, Ta1 any](name string, fn func(e *Interp, c Tc, a0 Ta0, a1 Ta1) gojq.Iter)

func ToBitReader added in v0.0.8

func ToBitReader(v any) (bitio.ReaderAtSeeker, error)

Types

type ArrayDecodeValue

type ArrayDecodeValue struct {
	gojqx.Base

	*decode.Compound
	// contains filtered or unexported fields
}

func NewArrayDecodeValue

func NewArrayDecodeValue(dv *decode.Value, out any, c *decode.Compound) ArrayDecodeValue

func (ArrayDecodeValue) DecodeValue

func (dvb ArrayDecodeValue) DecodeValue() *decode.Value

func (ArrayDecodeValue) Display

func (dvb ArrayDecodeValue) Display(w io.Writer, opts *Options) error

func (ArrayDecodeValue) ExtKeys

func (dvb ArrayDecodeValue) ExtKeys() []string

func (ArrayDecodeValue) ExtType added in v0.0.2

func (ArrayDecodeValue) ExtType() string

func (ArrayDecodeValue) JQValueEach

func (v ArrayDecodeValue) JQValueEach() any

func (ArrayDecodeValue) JQValueHas

func (v ArrayDecodeValue) JQValueHas(key any) any

func (ArrayDecodeValue) JQValueIndex

func (v ArrayDecodeValue) JQValueIndex(index int) any

func (ArrayDecodeValue) JQValueKey

func (v ArrayDecodeValue) JQValueKey(name string) any

func (ArrayDecodeValue) JQValueKeys

func (v ArrayDecodeValue) JQValueKeys() any

func (ArrayDecodeValue) JQValueLength

func (v ArrayDecodeValue) JQValueLength() any

func (ArrayDecodeValue) JQValueSlice

func (v ArrayDecodeValue) JQValueSlice(start int, end int) any

func (ArrayDecodeValue) JQValueSliceLen

func (v ArrayDecodeValue) JQValueSliceLen() any

func (ArrayDecodeValue) JQValueToGoJQ

func (v ArrayDecodeValue) JQValueToGoJQ() any

func (ArrayDecodeValue) JQValueToGoJQEx added in v0.6.0

func (v ArrayDecodeValue) JQValueToGoJQEx(optsFn func() (*Options, error)) any

func (ArrayDecodeValue) ToBinary added in v0.0.5

func (dvb ArrayDecodeValue) ToBinary() (Binary, error)

type Binary added in v0.0.5

type Binary struct {
	// contains filtered or unexported fields
}

func NewBinaryFromBitReader added in v0.0.8

func NewBinaryFromBitReader(br bitio.ReaderAtSeeker, unit int, pad int64) (Binary, error)

func (Binary) Display added in v0.0.5

func (b Binary) Display(w io.Writer, opts *Options) error

func (Binary) ExtKeys added in v0.0.5

func (Binary) ExtKeys() []string

func (Binary) ExtType added in v0.0.5

func (Binary) ExtType() string

func (Binary) JQValueEach added in v0.0.5

func (b Binary) JQValueEach() any

func (Binary) JQValueHas added in v0.0.5

func (b Binary) JQValueHas(key any) any

func (Binary) JQValueIndex added in v0.0.5

func (b Binary) JQValueIndex(index int) any

func (Binary) JQValueKey added in v0.0.5

func (b Binary) JQValueKey(name string) any

func (Binary) JQValueKeys added in v0.0.5

func (b Binary) JQValueKeys() any

func (Binary) JQValueLength added in v0.0.5

func (b Binary) JQValueLength() any

func (Binary) JQValueSlice added in v0.0.5

func (b Binary) JQValueSlice(start int, end int) any

func (Binary) JQValueSliceLen added in v0.0.5

func (b Binary) JQValueSliceLen() any

func (Binary) JQValueToGoJQ added in v0.0.5

func (b Binary) JQValueToGoJQ() any

func (Binary) JQValueToGoJQEx added in v0.7.0

func (b Binary) JQValueToGoJQEx(optsFn func() (*Options, error)) any

func (Binary) JQValueToNumber added in v0.0.5

func (b Binary) JQValueToNumber() any

func (Binary) JQValueToString added in v0.0.5

func (b Binary) JQValueToString() any

func (Binary) JQValueType added in v0.0.5

func (b Binary) JQValueType() string

func (Binary) ToBinary added in v0.0.5

func (b Binary) ToBinary() (Binary, error)

type CompleteFn added in v0.5.0

type CompleteFn func(line string, pos int) (newLine []string, shared int)

type DecodeValue

type DecodeValue interface {
	Value
	ToBinary

	DecodeValue() *decode.Value
}

TODO: redo/rename used by _isDecodeValue

type Decorator

type Decorator struct {
	Null      ansi.Code
	False     ansi.Code
	True      ansi.Code
	Number    ansi.Code
	String    ansi.Code
	ObjectKey ansi.Code
	Array     ansi.Code
	Object    ansi.Code

	Index ansi.Code
	Value ansi.Code

	DumpHeader ansi.Code
	DumpAddr   ansi.Code

	Error ansi.Code

	ValueColor func(v any) ansi.Code
	ByteColor  func(b byte) ansi.Code

	Column string
}

type Display

type Display interface {
	Display(w io.Writer, opts *Options) error
}

type EnvFuncFn added in v0.0.8

type EnvFuncFn func(env *Interp) gojqx.Function

type EvalInstance added in v0.0.8

type EvalInstance struct {
	Ctx          context.Context
	Output       io.Writer
	IsCompleting bool
	// contains filtered or unexported fields
}

type EvalOpts added in v0.0.5

type EvalOpts struct {
	// contains filtered or unexported fields
}

type Exiter

type Exiter interface {
	ExitCode() int
}

gojq errors can implement this to signal exit code

type FileReader

type FileReader struct {
	R        io.Reader
	FileInfo FixedFileInfo
}

func (FileReader) Close

func (FileReader) Close() error

func (FileReader) Read

func (rf FileReader) Read(p []byte) (int, error)

func (FileReader) Stat

func (rf FileReader) Stat() (fs.FileInfo, error)

type FixedFileInfo

type FixedFileInfo struct {
	FName    string
	FSize    int64
	FMode    fs.FileMode
	FModTime time.Time
	FIsDir   bool
	FSys     any
}

func (FixedFileInfo) IsDir

func (ffi FixedFileInfo) IsDir() bool

func (FixedFileInfo) ModTime

func (ffi FixedFileInfo) ModTime() time.Time

func (FixedFileInfo) Mode

func (ffi FixedFileInfo) Mode() fs.FileMode

func (FixedFileInfo) Name

func (ffi FixedFileInfo) Name() string

func (FixedFileInfo) Size

func (ffi FixedFileInfo) Size() int64

func (FixedFileInfo) Sys

func (ffi FixedFileInfo) Sys() any

type Input

type Input interface {
	fs.File
	Terminal
}

type Interp

type Interp struct {
	Registry *Registry
	OS       OS

	// new for each eval, other values are copied by value
	EvalInstance EvalInstance
	// contains filtered or unexported fields
}

func New

func New(os OS, registry *Registry) (*Interp, error)

func (*Interp) Eval

func (i *Interp) Eval(ctx context.Context, c any, expr string, opts EvalOpts) (gojq.Iter, error)

func (*Interp) EvalFunc

func (i *Interp) EvalFunc(ctx context.Context, c any, name string, args []any, opts EvalOpts) (gojq.Iter, error)

func (*Interp) EvalFuncValues

func (i *Interp) EvalFuncValues(ctx context.Context, c any, name string, args []any, opts EvalOpts) ([]any, error)

func (*Interp) Main

func (i *Interp) Main(ctx context.Context, output Output, versionStr string) error

func (*Interp) Stop

func (i *Interp) Stop()

type JQValueEx

type JQValueEx interface {
	gojq.JQValue
	JQValueToGoJQEx(optsFn func() (*Options, error)) any
}

type OS

type OS interface {
	Platform() Platform
	Stdin() Input
	Stdout() Output
	Stderr() Output
	InterruptChan() chan struct{}
	Args() []string
	Environ() []string
	ConfigDir() (string, error)
	// FS.File returned by FS().Open() can optionally implement io.Seeker
	FS() fs.FS
	Readline(opts ReadlineOpts) (string, error)
	History() ([]string, error)
}

type Options

type Options struct {
	Depth          int
	ArrayTruncate  int
	StringTruncate int
	Verbose        bool
	Width          int
	DecodeProgress bool
	Color          bool
	Colors         map[string]string
	ByteColors     []struct {
		Ranges [][2]int
		Value  string
	}
	Unicode      bool
	RawOutput    bool
	REPL         bool
	RawString    bool
	JoinString   string
	Compact      bool
	BitsFormat   string
	LineBytes    int
	DisplayBytes int
	Addrbase     int
	Sizebase     int
	SkipGaps     bool

	Decorator    Decorator
	BitsFormatFn func(br bitio.ReaderAtSeeker) (any, error)
}

func OptionsFromValue added in v0.0.8

func OptionsFromValue(v any) (*Options, error)

type Output

type Output interface {
	io.Writer
	Terminal
}

type Platform added in v0.0.5

type Platform struct {
	OS        string
	Arch      string
	GoVersion string
}

type ReadlineOpts added in v0.0.5

type ReadlineOpts struct {
	Prompt     string
	CompleteFn CompleteFn
}

type Registry added in v0.0.8

type Registry struct {
	EnvFuncFns []EnvFuncFn

	FSs []fs.ReadDirFS
	// contains filtered or unexported fields
}

func NewRegistry added in v0.0.8

func NewRegistry() *Registry

func (*Registry) FS added in v0.0.8

func (r *Registry) FS(fs fs.ReadDirFS)

func (*Registry) Format added in v0.0.8

func (r *Registry) Format(group *decode.Group, format *decode.Format) *decode.Format

func (*Registry) Func added in v0.0.8

func (r *Registry) Func(funcFn EnvFuncFn)

func (*Registry) Group added in v0.6.0

func (r *Registry) Group(name string) (*decode.Group, error)

func (*Registry) Groups added in v0.6.0

func (r *Registry) Groups() map[string]*decode.Group

func (*Registry) MustAll added in v0.0.8

func (r *Registry) MustAll() *decode.Group

func (*Registry) MustGroup added in v0.6.0

func (r *Registry) MustGroup(name string) *decode.Group

type RunMode

type RunMode int
const (
	ScriptMode RunMode = iota
	REPLMode
	CompletionMode
)

type StructDecodeValue

type StructDecodeValue struct {
	gojqx.Base

	*decode.Compound
	// contains filtered or unexported fields
}

func NewStructDecodeValue

func NewStructDecodeValue(dv *decode.Value, out any, c *decode.Compound) StructDecodeValue

func (StructDecodeValue) DecodeValue

func (dvb StructDecodeValue) DecodeValue() *decode.Value

func (StructDecodeValue) Display

func (dvb StructDecodeValue) Display(w io.Writer, opts *Options) error

func (StructDecodeValue) ExtKeys

func (dvb StructDecodeValue) ExtKeys() []string

func (StructDecodeValue) ExtType added in v0.0.2

func (StructDecodeValue) ExtType() string

func (StructDecodeValue) JQValueEach

func (v StructDecodeValue) JQValueEach() any

func (StructDecodeValue) JQValueHas

func (v StructDecodeValue) JQValueHas(key any) any

func (StructDecodeValue) JQValueKey

func (v StructDecodeValue) JQValueKey(name string) any

func (StructDecodeValue) JQValueKeys

func (v StructDecodeValue) JQValueKeys() any

func (StructDecodeValue) JQValueLength

func (v StructDecodeValue) JQValueLength() any

func (StructDecodeValue) JQValueSliceLen

func (v StructDecodeValue) JQValueSliceLen() any

func (StructDecodeValue) JQValueToGoJQ

func (v StructDecodeValue) JQValueToGoJQ() any

func (StructDecodeValue) JQValueToGoJQEx added in v0.6.0

func (v StructDecodeValue) JQValueToGoJQEx(optsFn func() (*Options, error)) any

func (StructDecodeValue) ToBinary added in v0.0.5

func (dvb StructDecodeValue) ToBinary() (Binary, error)

type Terminal

type Terminal interface {
	Size() (int, int)
	IsTerminal() bool
}

type ToBinary added in v0.0.5

type ToBinary interface {
	ToBinary() (Binary, error)
}

type Value

type Value interface {
	gojq.JQValue

	ExtType() string
	ExtKeys() []string
}

type Variable

type Variable struct {
	Name  string
	Value any
}

Jump to

Keyboard shortcuts

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