bracketconf

package module
v0.0.0-...-b35fc02 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2017 License: MIT Imports: 8 Imported by: 2

README

bracketconf GoDoc

A directive-based configuration parser

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(r io.Reader, filename string, dp DirectiveProcessor, out interface{}) (o interface{}, e error)

Parse parses a config from a reader using the given DirectiveProcessor for the root node into out Out is returned for convenience

func ParseFile

func ParseFile(filename string, dp DirectiveProcessor, out interface{}) (interface{}, error)

ParseFile parses a config file - like Parse but opens and reads from a file

Types

type ASTNode

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

ASTNode is an AST node

func ParseAST

func ParseAST(r io.Reader, filnename string) (a *ASTNode, err error)

ParseAST parses the data from an io.Reader into an AST and returns the root node

func ParseFileAST

func ParseFileAST(filename string) (*ASTNode, error)

ParseFileAST parses AST from a config at the given file path

func (ASTNode) Evaluate

func (a ASTNode) Evaluate(object interface{}, processor DirectiveProcessor)

Evaluate evaluates the directive or bracket into the provided object using the specified DirectiveProcessor

func (ASTNode) Float

func (a ASTNode) Float() float64

Float returns the value as a float64

func (ASTNode) ForEach

func (a ASTNode) ForEach(f func(i int, v ASTNode))

ForEach runs a function with each index-value pair in the array

func (ASTNode) Index

func (a ASTNode) Index(n int) ASTNode

Index returns the value in the array at index n If used on a bracketed value, it will return the n'th directive

func (ASTNode) Int

func (a ASTNode) Int() int

Int returns the value as an int

func (ASTNode) IsArr

func (a ASTNode) IsArr() bool

IsArr returns whether the ASTNode is an array value

func (ASTNode) IsBracket

func (a ASTNode) IsBracket() bool

IsBracket returns whether the ASTNode is a bracketed value

func (ASTNode) IsDir

func (a ASTNode) IsDir() bool

IsDir returns whether the ASTNode is a directive

func (ASTNode) IsValue

func (a ASTNode) IsValue() bool

IsValue returns whether the ASTNode is a value (array or otherwise)

func (ASTNode) Len

func (a ASTNode) Len() int

Len returns the number of elements in the array If used on a bracketed value, it will return the number of directives

func (ASTNode) Position

func (a ASTNode) Position() scanner.Position

Position returns the location of the value in the config file

func (ASTNode) Text

func (a ASTNode) Text() string

Text returns the value as a string

type ConfErr

type ConfErr struct {
	Pos scanner.Position
	Err error
}

ConfErr is an error type emitted in case of a parsing error

func (ConfErr) Error

func (ce ConfErr) Error() string

type Directive

type Directive struct {
	Name     string
	Callback func(object interface{}, ast ...ASTNode)
}

Directive is an object used to specify a directive to the AST processor

type DirectiveProcessor

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

DirectiveProcessor is a utility object used to execute directives

func NewDirectiveProcessor

func NewDirectiveProcessor(ds ...Directive) (dp DirectiveProcessor)

NewDirectiveProcessor creates a DirectiveProcessor using the specified set of directives

Jump to

Keyboard shortcuts

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