explain

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

README

Explain

Explain is an EXPERIMENTAL and a standalone package aimed to explain step by step operation in expr.

    s := "1 + 2 + 3"
    steps, err := explain.Explain(s)
    if err != nil {
        panic(err)
    }

    fmt.Printf("%#v\n", steps)
    /*
    []explain.Step{
       {[]string{"1 + 2"}, "3"},
       {[]string{"(1 + 2) + 3", "3 + 3"}, "6"},
    }
    */

    // explanation:
    // 1 + 2       -> 3
    // (1 + 2) + 3 -> (3 + 3) -> 6

Documentation

Overview

Package explain is a standalone package aimed to explain step by step operation in expr. This package is EXPERIMENTAL, and it's not guaranteed to be stable nor should it be maintained its backward compatibility.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Step

type Step struct {
	EquivalentForms []string
	Explaination    string
	Result          string
}

Step contains smaller operations of given s with its result. One step can have multiple equivalent forms, starts with original form until the final form.

func Explain

func Explain(s string) ([]Step, error)

Explains explains step-by-step process of evaluating s.

type Transform

type Transform struct {
	Segmented      string
	EquivalentForm string
	Explaination   string
	Evaluated      string
}

Transform holds transformation of operations result.

type Visitor

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

Visitor satisfies ast.Visitor and it will evaluate given expression in step-by-step transformation values.

func (*Visitor) Err

func (v *Visitor) Err() error

Err returns visitor's error

func (*Visitor) Value

func (v *Visitor) Value() []Transform

Value return []Transform

func (*Visitor) Visit

func (v *Visitor) Visit(node ast.Node) ast.Visitor

Jump to

Keyboard shortcuts

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