Documentation
¶
Overview ¶
Package rudi contains a convenience API to compile and execute Rudi programs.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewFunctionBuilder ¶ added in v0.3.0
NewFunctionBuilder is the recommended way to define new Rudi functions. The function builder can take multiple forms (e.g. if you have (foo INT) and (foo STRING)) and will create a function that automatically evaluates and coalesces Rudi expressions and matches them to the given forms. The first matching form is then evaluated.
Types ¶
type Coalescer ¶ added in v0.0.11
type Coalescer = coalescing.Coalescer
Coalescer is responsible for type handling and equality rules. Build your own or use any of the predefined versions:
- coalescing.NewStrict() – mostly strict, but allows nulls to be converted and allows ints to become floats
- coalescing.NewPedantic() – even more strict, allows absolutely no conversions
- coalescing.NewHumane() – gentle type handling that allows lossless conversions like 1 => "1" or allowing (false == nil).
type Context ¶
Context is the evaluation context for a Rudi program, consisting of the global document, variables and functions.
type Document ¶
Document is the global document that is being processed by a Rudi script.
func NewDocument ¶
NewDocument wraps any sort of data as a Rudi document.
type Function ¶
Function is a single Rudi function, available to be used inside a Rudi script.
func NewLowLevelFunction ¶ added in v0.3.0
func NewLowLevelFunction(f types.TupleFunction, description string) Function
NewLowLevelFunction wraps a raw tuple function to be used in Rudi. This is mostly useful for defining really low-level functions and functions with special side effects. Most of the time, you'd want to use NewFunctionBuilder(), which will use reflection to make it much more straight forward to make a Go function available in Rudi.
type Functions ¶
Functions is a map of Rudi functions.
func NewFunctions ¶
func NewFunctions() Functions
NewFunctions returns an empty set of runtime functions.
func NewSafeBuiltInFunctions ¶ added in v0.5.0
func NewSafeBuiltInFunctions() Functions
NewSafeBuiltInFunctions returns a copy of all the safe built-in Rudi functions. These are all the functions that do not break runtime guarantees like programs always terminating in a reasonable time. See also NewUnsafeBuiltInFunctions, which contains functions like func! that allow to define new functions within Rudi code, but could lead to infinite loops or resource exhaustion.
func NewUnsafeBuiltInFunctions ¶ added in v0.5.0
func NewUnsafeBuiltInFunctions() Functions
NewUnsafeBuiltInFunctions returns a copy of all the unsafe built-in Rudi functions. These are functions with extended side effects, please refer to the documentation or code for which functions exactly are considered "unsafe" in Rudi.
type ParseError ¶
type ParseError struct {
// contains filtered or unexported fields
}
ParseErrors can occur while parsing a Rudi program.
func (ParseError) Error ¶
func (p ParseError) Error() string
Error returns the underlying parse error.
func (ParseError) Snippet ¶
func (p ParseError) Snippet() string
Snippet is the line of the program where the error occurred, marked with a caret and the error message in a second line below that.
type Program ¶
type Program interface {
fmt.Stringer
// Run will evaluate the program. The given data value is used as the program's
// document (i.e. available with bare path expressions like `.foo`). Variables
// can be left empty if desired, but funcs must effectively always be set,
// as programs without functions are very limited. Use NewBuiltInFunctions()
// to get the default set of functions in Rudi.
// When no error occurs, Run() returns both the final document value and the
// result of the final expression. Otherwise an error is returned.
Run(ctx context.Context, data any, variables Variables, funcs Functions, coalescer Coalescer) (document any, result any, err error)
// RunContext is like Run(), but uses a pre-setup Context and returns the
// bare final context instead of its document's value. The result is still
// the result of the final expression in the program.
RunContext(ctx Context) (result any, err error)
// DumpSyntaxTree writes the AST to the given writer. Useful for debugging.
// Set indent to false to prevent multiline output from being generated
// according to a simple, conservative linebreak algorithm.
// Note that the output looks like code, but is not executable/parseable. Use
// DumpRudi() if you need to turn a parsed program back into Rudi code.
DumpSyntaxTree(out io.Writer) error
// DumpRudi writes the AST in the form of parseable Rudi code.
DumpRudi(out io.Writer) error
}
Program is a parsed Rudi program, ready to be run (executed). Programs are stateless and can be executed multiple times, even concurrently (as long as a different context is used per goroutine, when using RunContext).