interpreter

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExpectingStructInPointerFindOthers = "expecting struct inside pointer but find %s"
	ExpectingArrayInPointerFindOthers  = "expecting array inside pointer but find %s"
	FieldTypeNotMatchAST               = "field type %s is not of ast collection node type"
	FieldNotFound                      = "field with tag %s not found"
)
View Source
const (
	ExpectingStructFindOthers = "expecting struct but find %s"
	VariableNotFound          = "variable value for %s not found"
	FieldNotValid             = "field not exist %s"
	KVKindNotMatch            = "expect %s as key but value is not :%#v"
)

Variables

View Source
var (
	ErrorInterpreSymbolFailure           = errors.New("have symbol not consumed")
	ErrorInterpretVariable               = errors.New("error when interpret variable values")
	ErrorInternalInterpreterOutdated     = errors.New("interpreter not update as the ast grows")
	ErrorKeyStringVariableNotResolve     = errors.New("find string variable as object key, but the variable value is missing")
	ErrorVariableValueNotJsonValueType   = errors.New("variable value should be json value type")
	ErrorVariableValueNotFound           = errors.New("variable value is not found")
	ErrorInternalGetPrimitiveValue       = errors.New("try to get primitive value from none-primitive type")
	ErrorInternalShouldBeArrayOrSlice    = errors.New("should be array or slice")
	ErrorInternalMapKeyTypeNotMatchValue = fmt.Errorf("expect bool as key but value is not bool")

	ErrorInternalExpectingPrimitive     = errors.New("expecting primitive values but find others")
	ErrorInternalPtrToArrayFindNotArray = errors.New("expecting pointer to array, but underlying object not array")
	ErrSliceOrArrayNotInit              = errors.New("slice/array not init")
	ErrorUnmarshalStackNoKV             = errors.New("there should not be kv pair in stack")
	ErrorNotSupportedASTNode            = errors.New("not supported ast node")
	ErrorInternalSymbolStackIncorrect   = errors.New("interpret symbol stack invalid")
)
View Source
var (
	ErrorReflectNotObject     = errors.New("out element is not map nor struct")
	ErrorReflectInvalidMapKey = errors.New("map key type should be string")
	ErrOutNotNilPointer       = errors.New("out is nil pointer")
)
View Source
var (
	ErrOutNotPointer                                   = errors.New("out is not pointer")
	ErrorInternalNoneResolvable                        = errors.New("expecting dependendent element to resolve")
	ErrorInternalUnsupportedMapKeyKind                 = fmt.Errorf("unsupported map key to continue")
	ErrorStringVariableNotResolveOnKeyLocation         = errors.New("object key contain string variable that has no variable value")
	ErrorInternalDependentResolverHasOnResolveLocation = errors.New("dependent value has no idex or object key set to resolve")
	ErrorPrimitiveTypeCannotResolveDependency          = errors.New("pritimive type cannot resolve dependency")
	ErrorInternalExpectingArrayLikeObject              = errors.New("expecting array like object but find others")
	ErrorInvalidUnmarshalResult                        = errors.New("invalid unmarshal result")
	ErrorInvalidTag                                    = errors.New("invalid json tag")
	ErrorUnsupportedDataKind                           = errors.New("unsupported variable data kind")
	ErrorInvalidJson                                   = errors.New("invalid json")
	ErrorSelfCallTooDeep                               = errors.New("recursion depth exceeded")
)
View Source
var (
	ErrorUnmarshalNotSlice = errors.New("unmarshal to a non-slice variable")
)

Functions

func InterpretAST added in v0.3.2

func InterpretAST(node ast.JsonNode, variables map[string]interface{}, marshaler ast.MarshalerFunc) ([]byte, error)

func Marshal added in v0.4.0

func Marshal(v interface{}) ([]byte, error)

func MarshalIntoTemplate added in v0.5.0

func MarshalIntoTemplate(v interface{}) ([]byte, error)

func MarshalWithVariables added in v0.5.1

func MarshalWithVariables(v interface{}, variables map[string]interface{}) ([]byte, error)

func NewASTInterpreter added in v0.4.0

func NewASTInterpreter(variables map[string]interface{}, marshaler ast.MarshalerFunc) *standardVisitor

func NewErrFieldCannotSetOrNotfound added in v0.3.0

func NewErrFieldCannotSetOrNotfound(fieldName string) error

func NewErrorFieldNotFound added in v0.3.1

func NewErrorFieldNotFound(field string) error

func NewErrorFiledNotFound added in v0.3.0

func NewErrorFiledNotFound(fieldName string) error

func NewErrorInternalExpectingArrayInsidePointerButFindOthers added in v0.3.0

func NewErrorInternalExpectingArrayInsidePointerButFindOthers(kind string) error

func NewErrorInternalExpectingStructButFindOthers added in v0.3.0

func NewErrorInternalExpectingStructButFindOthers(kind string) error

func NewErrorInternalExpectingStructInsidePointerButFindOthers added in v0.3.0

func NewErrorInternalExpectingStructInsidePointerButFindOthers(kind string) error

func NewErrorInternalFieldTypeNotMatchAST added in v0.3.0

func NewErrorInternalFieldTypeNotMatchAST(kind string) error

func NewErrorInternalMapKeyValueKindNotMatch added in v0.3.0

func NewErrorInternalMapKeyValueKindNotMatch(kind string, value interface{}) error

func NewUnMarshallOptions added in v0.3.0

func NewUnMarshallOptions(variables map[string]interface{}, marshaler ast.MarshalerFunc, unmarshaler ast.UnmarshalerFunc) *unmarshallOptions

func NewVariableNotFound added in v0.3.0

func NewVariableNotFound(variable string) error

func ParseJsonExtendDocument added in v0.4.1

func ParseJsonExtendDocument(reader io.Reader, variables map[string]interface{}) ([]byte, error)

func PrettyInterpret added in v0.3.2

func PrettyInterpret(node ast.JsonNode, variables map[string]interface{}, marshaler ast.MarshalerFunc) ([]byte, error)

func Unmarshal added in v0.4.0

func Unmarshal(reader io.Reader, variables map[string]interface{}, out interface{}) error

func UnmarshallAST added in v0.3.0

func UnmarshallAST(node ast.JsonNode, variables map[string]interface{}, marshaler ast.MarshalerFunc, unmarshaler ast.UnmarshalerFunc, out interface{}) error

use marshaler to deal with the string variable/variable, use unmarshaler to deal with the json tag `string` option

Types

type BufferWriter added in v0.4.0

type BufferWriter interface {
	Write(p []byte) (n int, err error)
	WriteByte(c byte) error
	WriteString(s string) (n int, err error)
	Bytes() []byte
}

type ErrorFieldNotExist added in v0.4.0

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

func NewErrorFieldNotValid added in v0.3.0

func NewErrorFieldNotValid(field string) ErrorFieldNotExist

func (ErrorFieldNotExist) Error added in v0.4.0

func (e ErrorFieldNotExist) Error() string

type PrettyPrintVisitor added in v0.4.0

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

func NewPPInterpreter added in v0.3.2

func NewPPInterpreter(variables map[string]interface{}, marshaler ast.MarshalerFunc) *PrettyPrintVisitor

func (*PrettyPrintVisitor) GetOutput added in v0.4.0

func (s *PrettyPrintVisitor) GetOutput() []byte

func (*PrettyPrintVisitor) VisitArrayNode added in v0.4.0

func (s *PrettyPrintVisitor) VisitArrayNode(node *ast.JsonArrayNode) error

func (*PrettyPrintVisitor) VisitBooleanNode added in v0.4.0

func (s *PrettyPrintVisitor) VisitBooleanNode(node *ast.JsonBooleanNode) error

func (*PrettyPrintVisitor) VisitKeyValuePairNode added in v0.4.0

func (s *PrettyPrintVisitor) VisitKeyValuePairNode(node *ast.JsonKeyValuePairNode) error

func (*PrettyPrintVisitor) VisitNullNode added in v0.4.0

func (s *PrettyPrintVisitor) VisitNullNode(node *ast.JsonNullNode) error

func (*PrettyPrintVisitor) VisitNumberNode added in v0.4.0

func (s *PrettyPrintVisitor) VisitNumberNode(node *ast.JsonNumberNode) error

func (*PrettyPrintVisitor) VisitObjectNode added in v0.4.0

func (s *PrettyPrintVisitor) VisitObjectNode(node *ast.JsonObjectNode) error

func (*PrettyPrintVisitor) VisitStringNode added in v0.4.0

func (s *PrettyPrintVisitor) VisitStringNode(node *ast.JsonStringNode) error

func (*PrettyPrintVisitor) VisitStringWithVariableNode added in v0.4.0

func (s *PrettyPrintVisitor) VisitStringWithVariableNode(node *ast.JsonExtendedStringWIthVariableNode) error

func (*PrettyPrintVisitor) VisitVariableNode added in v0.4.0

func (s *PrettyPrintVisitor) VisitVariableNode(node *ast.JsonExtendedVariableNode) error

func (*PrettyPrintVisitor) WriteSymbol added in v0.4.0

func (s *PrettyPrintVisitor) WriteSymbol() error

Jump to

Keyboard shortcuts

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