jsonte

package
v0.0.0-...-c879681 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultIndexName = "index"
View Source
const DefaultName = "value"
View Source
const MaxInt64 = int64(^uint64(0) >> 1)
View Source
const WrongTypeErrTag = "wrong_type"

Variables

This section is empty.

Functions

func FetchCache

func FetchCache() error

FetchCache caches the vanilla packs

func FindAnyCase

func FindAnyCase[T types.JsonType](o *types.JsonObject, key ...string) (*T, error)

FindAnyCase returns the first key that matches the given key, ignoring case.

func LibraryInit

func LibraryInit(level zapcore.Level, safeMode bool)

LibraryInit initializes jsonte in library mode level is the logging level safeMode is whether to run in safe mode, which disables unsafe functions

func ParseLambda

func ParseLambda(text string) ([]string, []string, error)

func Process

func Process(name, input string, globalScope *types.JsonObject, modules map[string]JsonModule, timeout int64) (utils.NavigableMap[string, *types.JsonObject], error)

Process processes a template and returns a map of the processed templates

func ProcessAssertionsFile

func ProcessAssertionsFile(name, input string, globalScope *types.JsonObject, timeout int64) error

func ProcessLangFile

func ProcessLangFile(input string, scope *types.JsonObject) (string, error)

ProcessLangFile processes a lang file replacing all the jsonte expressions with their values

func ProcessMCFunction

func ProcessMCFunction(input string, scope *types.JsonObject) (string, error)

ProcessMCFunction processes a file replacing all the jsonte expressions with their values

func ProcessString

func ProcessString(input string, scope *types.JsonObject, startToken, endToken string) (string, error)

ProcessString processes a string replacing all the jsonte expressions with their values

func PutValue

func PutValue(result *types.JsonObject, key string, r types.JsonType, path string) error

func UnescapeString

func UnescapeString(text string) string

func UnescapeStringToBuffer

func UnescapeStringToBuffer(text []rune, sb *strings.Builder, i *int, end rune) (bool, string)

UnescapeStringToBuffer unescapes a string to a buffer. If end is not 0, the unescaping will stop when the end rune is found. Returns true if the end rune is found and false otherwise. Also returns the escaped string for debugging purposes.

func VerifyReservedNames

func VerifyReservedNames(o *types.JsonObject, path string) error

Types

type CollectingErrorListener

type CollectingErrorListener struct {
	*antlr.DefaultErrorListener
	Error error
}

CollectingErrorListener is an error listener that collects all errors by appending them to the Error field

func (*CollectingErrorListener) SyntaxError

func (l *CollectingErrorListener) SyntaxError(recognizer antlr.Recognizer, offendingSymbol interface{}, line, column int, msg string, e antlr.RecognitionException)

type ExpressionVisitor

type ExpressionVisitor struct {
	parser.BaseJsonTemplateVisitor
	// contains filtered or unexported fields
}

func (*ExpressionVisitor) ResolveScope

func (v *ExpressionVisitor) ResolveScope(name string) types.JsonType

ResolveScope resolves a value from the scope by name

func (*ExpressionVisitor) Visit

func (v *ExpressionVisitor) Visit(tree antlr.ParseTree) (types.JsonType, error)

func (*ExpressionVisitor) VisitArray

func (v *ExpressionVisitor) VisitArray(context *parser.ArrayContext) (types.JsonType, error)

func (*ExpressionVisitor) VisitExpression

func (v *ExpressionVisitor) VisitExpression(ctx *parser.ExpressionContext) (types.JsonType, error)

func (*ExpressionVisitor) VisitField

func (v *ExpressionVisitor) VisitField(context *parser.FieldContext) (types.JsonType, error)

func (*ExpressionVisitor) VisitFunction_param

func (v *ExpressionVisitor) VisitFunction_param(ctx *parser.Function_paramContext) (types.JsonType, error)

func (*ExpressionVisitor) VisitIndex

func (v *ExpressionVisitor) VisitIndex(context *parser.IndexContext) (types.JsonType, error)

func (*ExpressionVisitor) VisitLambda

func (v *ExpressionVisitor) VisitLambda(ctx *parser.LambdaContext) (types.JsonType, error)

func (*ExpressionVisitor) VisitName

func (v *ExpressionVisitor) VisitName(context *parser.NameContext) (types.JsonType, error)

func (*ExpressionVisitor) VisitObject

func (v *ExpressionVisitor) VisitObject(context *parser.ObjectContext) (types.JsonType, error)

func (*ExpressionVisitor) VisitObject_field

func (v *ExpressionVisitor) VisitObject_field(context *parser.Object_fieldContext) (types.JsonType, error)

func (*ExpressionVisitor) VisitScript

func (v *ExpressionVisitor) VisitScript(ctx *parser.ScriptContext) (types.JsonType, error)

func (*ExpressionVisitor) VisitStatement

func (v *ExpressionVisitor) VisitStatement(ctx *parser.StatementContext) (types.JsonType, error)

func (*ExpressionVisitor) VisitStatements

func (v *ExpressionVisitor) VisitStatements(ctx *parser.StatementsContext) (types.JsonType, error)

type JsonModule

type JsonModule struct {
	Name     *types.JsonString
	Scope    *types.JsonObject
	Template *types.JsonObject
	Copy     *types.JsonString
}

JsonModule represents a module that can be extended by a template

func LoadModule

func LoadModule(input string, globalScope *types.JsonObject, timeout int64) (JsonModule, error)

LoadModule loads a module from a file and returns a JsonModule

type LambdaVisitor

type LambdaVisitor struct {
	parser.BaseJsonTemplateVisitor
	// contains filtered or unexported fields
}

func (*LambdaVisitor) Visit

func (v *LambdaVisitor) Visit(tree antlr.ParseTree)

func (*LambdaVisitor) VisitArray

func (v *LambdaVisitor) VisitArray(context *parser.ArrayContext)

func (*LambdaVisitor) VisitExpression

func (v *LambdaVisitor) VisitExpression(ctx *parser.ExpressionContext)

func (*LambdaVisitor) VisitField

func (v *LambdaVisitor) VisitField(context *parser.FieldContext)

func (*LambdaVisitor) VisitFunction_param

func (v *LambdaVisitor) VisitFunction_param(ctx *parser.Function_paramContext)

func (*LambdaVisitor) VisitIndex

func (v *LambdaVisitor) VisitIndex(context *parser.IndexContext)

func (*LambdaVisitor) VisitLambda

func (v *LambdaVisitor) VisitLambda(ctx *parser.LambdaContext)

func (*LambdaVisitor) VisitObject

func (v *LambdaVisitor) VisitObject(context *parser.ObjectContext)

func (*LambdaVisitor) VisitObject_field

func (v *LambdaVisitor) VisitObject_field(context *parser.Object_fieldContext)

type Result

type Result struct {
	Value         types.JsonType
	Action        types.JsonAction
	Name          string
	IndexName     string
	Scope         deque.Deque[*types.JsonObject]
	VariableScope *types.JsonObject
}

Result is the result of evaluating an expression

func Eval

func Eval(text string, scope deque.Deque[*types.JsonObject], path string) (Result, error)

Eval evaluates the given expression and returns the result

func EvalScript

func EvalScript(text string, scope deque.Deque[*types.JsonObject], path string) (Result, error)

EvalScript evaluates the given script and returns the result

func EvalWithTempScope

func EvalWithTempScope(text string, scope deque.Deque[*types.JsonObject], path string, temp ...*types.JsonObject) (Result, error)

EvalWithTempScope evaluates the given expression and returns the result

func QuickEval

func QuickEval(text string, path string) (Result, error)

QuickEval is a convenience function for evaluating a single expression

func (*Result) GetError

func (r *Result) GetError() error

GetError returns the error from the result or nil if the expression evaluated correctly

type TemplateMatch

type TemplateMatch struct {
	Match        string
	EscapedMatch string
	Start        int
	Length       int
}

func FindTemplateMatches

func FindTemplateMatches(input, startToken, endToken string) ([]TemplateMatch, error)

FindTemplateMatches processes a string replacing all the jsonte expressions with their values

type TemplateVisitor

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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