ast

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AST_STATE_INIT astState = iota
	AST_STATE_INTERMIDIEATE
	AST_STATE_FINISHED
)
View Source
const (
	AST_NODE_TYPE_BOUNDARY = 200
	AST_ARRAY              = 201
	AST_OBJECT             = 202
	AST_KVPAIR             = 203
	AST_VARIABLE           = 204
	AST_STRING_VARIABLE    = 205
	AST_STRING             = 206
	AST_NUMBER             = 207
	AST_BOOLEAN            = 208
	AST_NULL               = 209
	AST_NODE_UNDEFINED     = 210
)

Variables

View Source
var (
	ErrorASTComplete                          = errors.New("cannot create new ast node when the ast has finished")
	ErrorASTStackInvalidElement               = errors.New("ast trace stack will only contain: kv, array, object, no primitive values")
	ErrorASTUnexpectedElement                 = errors.New("unexecpted stack element type")
	ErrorASTUnexpectedOwnerElement            = errors.New("unexecpted stack owner element type")
	ErrorASTStackEmpty                        = errors.New("unexecpted stack empty")
	ErrorASTEncloseElementType                = errors.New("enclose element type must be array or object")
	ErrorASTIncorrectNodeType                 = errors.New("incorrect node type")
	ErrorIncorrectSyntaxSymbolForConstructAST = errors.New("incorrect character for construct ast")
)
View Source
var (
	ErrorSyntaxEmptyStack                  = errors.New("empty syntax stack")
	ErrorSyntaxEncloseIncorrectSymbol      = errors.New("invalid operation, not ]|} to enclose")
	ErrorSyntaxEncloseSymbolNotMatch       = errors.New("enclose symbol not match")
	ErrorSyntaxEncloseSymbolIncorrect      = errors.New("enclose symbol incorrect")
	ErrorSyntaxCommaBehindLastItem         = errors.New("find `,]` or `,}` in the syntax checker")
	ErrorSyntaxElementNotSeparatedByComma  = errors.New("syntax element not separated by comma")
	ErrorSyntaxUnexpectedSymbolInArray     = errors.New("unexpected symbol in array")
	ErrorSyntaxExtendedSyntaxVariableAsKey = errors.New("extended syntax variable as key")
	ErrorSyntaxObjectSymbolNotMatch        = errors.New("object symbol not match")
)

Functions

This section is empty.

Types

type ASTConstructor

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

func NewASTConstructor

func NewASTConstructor() *ASTConstructor

func (*ASTConstructor) GetAST

func (i *ASTConstructor) GetAST() JsonNode

func (*ASTConstructor) HasComplete

func (i *ASTConstructor) HasComplete() bool

func (*ASTConstructor) HasOpenElements

func (i *ASTConstructor) HasOpenElements() bool

func (*ASTConstructor) RecordSyntaxSymbol

func (i *ASTConstructor) RecordSyntaxSymbol(b byte) error

when a json symbol is read, push it to syntax checker and construct the AST stack elements (as described in ast.go)

func (*ASTConstructor) RecordSyntaxValue

func (i *ASTConstructor) RecordSyntaxValue(valueType AST_NODETYPE, nodeValue interface{}) error

func (*ASTConstructor) TopElementType

func (i *ASTConstructor) TopElementType() (AST_NODETYPE, error)

type AST_NODETYPE

type AST_NODETYPE byte

type JsonArrayNode

type JsonArrayNode struct {
	Value []JsonNode
}

func (*JsonArrayNode) Append

func (node *JsonArrayNode) Append(n JsonNode)

func (*JsonArrayNode) GetNodeType

func (node *JsonArrayNode) GetNodeType() AST_NODETYPE

func (*JsonArrayNode) Visit

func (node *JsonArrayNode) Visit(visitor JsonVisitor)

type JsonBooleanNode

type JsonBooleanNode struct {
	Value bool
}

func (*JsonBooleanNode) GetNodeType

func (node *JsonBooleanNode) GetNodeType() AST_NODETYPE

func (*JsonBooleanNode) Visit

func (node *JsonBooleanNode) Visit(visitor JsonVisitor)

type JsonExtendedStringWIthVariableNode

type JsonExtendedStringWIthVariableNode struct {
	JsonStringNode
	Variables map[string][]byte
}

func (*JsonExtendedStringWIthVariableNode) GetNodeType

func (*JsonExtendedStringWIthVariableNode) Visit

func (node *JsonExtendedStringWIthVariableNode) Visit(visitor JsonVisitor)

type JsonExtendedVariableNode

type JsonExtendedVariableNode struct {
	Value    []byte
	Variable string
}

func (*JsonExtendedVariableNode) GetNodeType

func (node *JsonExtendedVariableNode) GetNodeType() AST_NODETYPE

func (*JsonExtendedVariableNode) Visit

func (node *JsonExtendedVariableNode) Visit(visitor JsonVisitor)

type JsonKeyValuePairNode

type JsonKeyValuePairNode struct {
	Key   JsonNode
	Value JsonNode
}

func (*JsonKeyValuePairNode) GetNodeType

func (node *JsonKeyValuePairNode) GetNodeType() AST_NODETYPE

func (*JsonKeyValuePairNode) IsFilled

func (node *JsonKeyValuePairNode) IsFilled() bool

func (*JsonKeyValuePairNode) Visit

func (node *JsonKeyValuePairNode) Visit(visitor JsonVisitor)

type JsonNode

type JsonNode interface {
	GetNodeType() AST_NODETYPE
	Visit(visitor JsonVisitor)
}

type JsonNullNode

type JsonNullNode struct {
	Value interface{}
}

func (*JsonNullNode) GetNodeType

func (node *JsonNullNode) GetNodeType() AST_NODETYPE

func (*JsonNullNode) Visit

func (node *JsonNullNode) Visit(visitor JsonVisitor)

type JsonNumberNode

type JsonNumberNode struct {
	Value float64
}

func (*JsonNumberNode) GetNodeType

func (node *JsonNumberNode) GetNodeType() AST_NODETYPE

func (*JsonNumberNode) Visit

func (node *JsonNumberNode) Visit(visitor JsonVisitor)

type JsonObjectNode

type JsonObjectNode struct {
	Value []*JsonKeyValuePairNode
}

func (*JsonObjectNode) Append

func (node *JsonObjectNode) Append(kvNode *JsonKeyValuePairNode)

func (*JsonObjectNode) GetNodeType

func (node *JsonObjectNode) GetNodeType() AST_NODETYPE

func (*JsonObjectNode) Visit

func (node *JsonObjectNode) Visit(visitor JsonVisitor)

type JsonStringNode

type JsonStringNode struct {
	Value []byte
}

func (*JsonStringNode) GetNodeType

func (node *JsonStringNode) GetNodeType() AST_NODETYPE

func (*JsonStringNode) Visit

func (node *JsonStringNode) Visit(visitor JsonVisitor)

type JsonVisitor

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

Jump to

Keyboard shortcuts

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