ast

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	V_NONE   = 0
	V_NULL   = 2
	V_TRUE   = 3
	V_FALSE  = 4
	V_ARRAY  = 5
	V_OBJECT = 6
	V_STRING = 7
	V_NUMBER = int(_V_NUMBER)
)

Variables

This section is empty.

Functions

func Loads

func Loads(src string) (int, interface{}, types.ParsingError)

Loads parse all json into interface{}

func LoadsUseNumber

func LoadsUseNumber(src string) (int, interface{}, types.ParsingError)

LoadsUseNumber parse all json into interface{}, with numeric nodes casted to json.Number

Types

type Iterator

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

func (*Iterator) HasNext

func (self *Iterator) HasNext() bool

func (*Iterator) Len

func (self *Iterator) Len() int

func (*Iterator) Pos

func (self *Iterator) Pos() int

type ListIterator

type ListIterator struct {
	Iterator
}

func (*ListIterator) Next

func (self *ListIterator) Next(v *Node) bool

type Node

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

func NewArray

func NewArray(v []Node) Node

NewArray creates a node of type V_ARRAY, using v as its underlying children

func NewBool

func NewBool(v bool) Node

NewBool creates a node of type bool:

If v is true, returns V_TRUE node
If v is false, returns V_FALSE node

func NewNull

func NewNull() Node

NewNull creates a node of type V_NULL

func NewNumber

func NewNumber(v string) Node

NewNumber creates a json.Number node v must be a decimal string complying with RFC8259

func NewObject

func NewObject(v []Pair) Node

NewObject creates a node of type V_OBJECT, using v as its underlying children

func NewString

func NewString(v string) Node

NewString creates a node of type string

func (*Node) Add

func (self *Node) Add(node Node)

Add appends the given node under array node

func (*Node) Array

func (self *Node) Array() []interface{}

Array loads all indexes of an array node

func (*Node) ArrayUseNode

func (self *Node) ArrayUseNode() []Node

ArrayUseNode copys both parsed and non-parsed chidren nodes, and indexes them by original order

func (*Node) ArrayUseNumber

func (self *Node) ArrayUseNumber() []interface{}

ArrayUseNumber loads all indexes of an array node, with numeric nodes casted to json.Number

func (*Node) Bool

func (self *Node) Bool() bool

Bool returns bool value represented by this node

If node type is not types.V_TRUE or types.V_FALSE, or V_RAW (must be a bool json value) it will panic

func (*Node) Cap

func (self *Node) Cap() int

Cap returns malloc capacity of a array|object node for children

func (*Node) Exists

func (self *Node) Exists() bool

Exists returns false only if the node is nil or got by invalid path

func (*Node) Float64

func (self *Node) Float64() float64

Float64 as above.

func (*Node) Get

func (self *Node) Get(key string) *Node

Get loads given key of an object node on demands

func (*Node) GetByPath

func (self *Node) GetByPath(path ...interface{}) *Node

GetByPath load given path on demands, which only ensure nodes before this path got parsed

func (*Node) Index

func (self *Node) Index(idx int) *Node

Index loads given index of an node on demands, node type can be either V_OBJECT or V_ARRAY

func (*Node) Int64

func (self *Node) Int64() int64

Int64 as above.

func (*Node) Interface

func (self *Node) Interface() interface{}

Interface loads all children under all pathes from this node, and converts itself as generic go type all numberic nodes are casted to float64

func (*Node) InterfaceUseNode

func (self *Node) InterfaceUseNode() interface{}

InterfaceUseNode clone itself as a new node, or its children as map[string]Node (or []Node)

func (*Node) InterfaceUseNumber

func (self *Node) InterfaceUseNumber() interface{}

InterfaceUseNumber works same with Interface() except numberic nodes are casted to json.Number

func (Node) IsRaw

func (self Node) IsRaw() bool

IsRaw returns true if node's underlying value is raw json

func (*Node) Len

func (self *Node) Len() int

Len returns children count of a array|object|string node For partially loaded node, it also works but only counts the parsed children

func (*Node) Map

func (self *Node) Map() map[string]interface{}

Map loads all keys of an object node

func (*Node) MapUseNode

func (self *Node) MapUseNode() map[string]Node

MapUseNode scans both parsed and non-parsed chidren nodes, and map them by their keys

func (*Node) MapUseNumber

func (self *Node) MapUseNumber() map[string]interface{}

MapUseNumber loads all keys of an object node, with numeric nodes casted to json.Number

func (*Node) MarshalJSON

func (self *Node) MarshalJSON() ([]byte, error)

func (*Node) Number

func (self *Node) Number() json.Number

Number as above.

func (*Node) Properties

func (self *Node) Properties() ObjectIterator

Properties returns iterator for object's children traversal

func (Node) Raw

func (self Node) Raw() string

Raw returns underlying json string of an raw node, which usually created by Search() api

func (*Node) Set

func (self *Node) Set(key string, node Node)

Set sets the node of given key under object parent If the key doesn't exist, it will be append to the last

func (*Node) SetByIndex

func (self *Node) SetByIndex(index int, node Node)

SetByIndex sets the node of given index

The index must within parent array's children

func (*Node) String

func (self *Node) String() string

String as above.

func (Node) Type

func (self Node) Type() int

Type returns json type represented by the node It will be one of belows:

V_NONE   = 0
V_NULL   = 2
V_TRUE   = 3
V_FALSE  = 4
V_ARRAY  = 5
V_OBJECT = 6
V_STRING = 7
V_NUMBER = 33

func (*Node) UnsafeArray

func (self *Node) UnsafeArray() []Node

ArrayUnsafe exports the underlying pointer to its children array WARN: don't use it unless you know what you are doing

func (*Node) UnsafeMap

func (self *Node) UnsafeMap() []Pair

MapUnsafe exports the underlying pointer to its children map WARN: don't use it unless you know what you are doing

func (*Node) Unset

func (self *Node) Unset(key string) (exist bool)

Unset remove the node of given key under object parent

func (*Node) UnsetByIndex

func (self *Node) UnsetByIndex(index int) (exist bool)

UnsetByIndex remove the node of given index

func (*Node) Values

func (self *Node) Values() ListIterator

Values returns iterator for array's children traversal

type ObjectIterator

type ObjectIterator struct {
	Iterator
}

func (*ObjectIterator) Next

func (self *ObjectIterator) Next(p *Pair) bool

type Pair

type Pair struct {
	Key   string
	Value Node
}

type Parser

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

func NewParser

func NewParser(src string) *Parser

func (*Parser) ExportError

func (self *Parser) ExportError(err types.ParsingError) error

ExportError converts types.ParsingError to std Error

func (*Parser) Parse

func (self *Parser) Parse() (Node, types.ParsingError)

func (*Parser) Pos

func (self *Parser) Pos() int

type Searcher

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

func NewSearcher

func NewSearcher(str string) *Searcher

func (*Searcher) GetByPath

func (self *Searcher) GetByPath(path ...interface{}) (Node, error)

Jump to

Keyboard shortcuts

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