interpreter

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

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

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")
	ErrorInternalUnsupportedMapKeyKind   = fmt.Errorf("unsupported map key to continue")
	ErrorInternalMapKeyTypeNotMatchValue = fmt.Errorf("expect bool as key but value is not bool")

	ErrorStringVariableNotResolveOnKeyLocation         = errors.New("object key contain string variable that has no variable value")
	ErrorInternalExpectingPrimitive                    = errors.New("expecting primitive values but find others")
	ErrorInternalPtrToArrayFindNotArray                = errors.New("expecting pointer to array, but underlying object not array")
	ErrorInternalExpectingArrayLikeObject              = errors.New("expecting array like object but find others")
	ErrSliceOrArrayNotInit                             = errors.New("slice/array not init")
	ErrorUnmarshalStackNoKV                            = errors.New("there should not be kv pair in stack")
	ErrorInternalNoneResolvable                        = errors.New("expecting dependendent element to resolve")
	ErrorPrimitiveTypeCannotResolveDependency          = errors.New("pritimive type cannot resolve dependency")
	ErrorNotSupportedASTNode                           = errors.New("not supported ast node")
	ErrorInternalDependentResolverHasOnResolveLocation = errors.New("dependent value has no idex or object key set to resolve")
)
View Source
var (
	ErrorReflectNotObject     = errors.New("out element is not map nor struct")
	ErrorReflectInvalidMapKey = errors.New("map key type should be string")
	ErrOutNotPointer          = errors.New("out is not pointer")
	ErrOutNotNilPointer       = errors.New("out is nil pointer")
)
View Source
var (
	ErrorUnmarshalNotSlice = errors.New("unmarshal to a non-slice variable")
)

Functions

func Interpret

func Interpret(node ast.JsonNode, variables map[string]interface{}) (string, error)

func NewErrFieldCannotSetOrNotfound added in v0.3.0

func NewErrFieldCannotSetOrNotfound(fieldName string) error

func NewErrorFieldNotValid added in v0.3.0

func NewErrorFieldNotValid(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 NewInterpreter

func NewInterpreter(variables map[string]interface{}) *standardVisitor

func NewUnMarshallOptions added in v0.3.0

func NewUnMarshallOptions(variables map[string]interface{}) *unmarshallOptions

func NewVariableNotFound added in v0.3.0

func NewVariableNotFound(variable string) error

func UnmarshallAST added in v0.3.0

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

Types

type JsonVisitor

type JsonVisitor interface {
	VisitStringNode(node *ast.JsonStringNode) error
	VisitNumberNode(node *ast.JsonNumberNode) error
	VisitBooleanNode(node *ast.JsonBooleanNode) error
	VisitNullNode(node *ast.JsonNullNode) error
	VisitArrayNode(node *ast.JsonArrayNode) error
	VisitKeyValuePairNode(node *ast.JsonKeyValuePairNode) error
	VisitObjectNode(node *ast.JsonObjectNode) error
	VisitVariableNode(node *ast.JsonExtendedVariableNode) error
	VisitStringWithVariableNode(node *ast.JsonExtendedStringWIthVariableNode) error
}

Jump to

Keyboard shortcuts

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