grammar

package
v0.1.12-beta Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2023 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SelectorTypeUnknown = iota
	SelectorTypeBexpr
	SelectorTypeJsonPointer
)
View Source
const (
	ValueTypeUndefined = iota
	ValueTypeBool
	ValueTypeInt
	ValueTypeUint
	ValueTypeFloat32
	ValueTypeFloat64
	ValueTypeString
	ValueTypeReflect
)

Variables

This section is empty.

Functions

func Parse

func Parse(filename string, b []byte, opts ...Option) (interface{}, error)

Parse parses the data from b using filename as information in the error messages.

func ParseFile

func ParseFile(filename string, opts ...Option) (i interface{}, err error)

ParseFile parses the file identified by filename.

func ParseReader

func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error)

ParseReader parses the data from r using filename as information in the error messages.

Types

type BinaryExpression

type BinaryExpression struct {
	Left     Expression
	Operator BinaryOperator
	Right    Expression
}

func (*BinaryExpression) ExpressionDump

func (expr *BinaryExpression) ExpressionDump(w io.Writer, indent string, level int)

type BinaryOperator

type BinaryOperator int
const (
	BinaryOpAnd BinaryOperator = iota
	BinaryOpOr
)

func (BinaryOperator) String

func (op BinaryOperator) String() string

type Expression

type Expression interface {
	ExpressionDump(w io.Writer, indent string, level int)
}

type ExpressionValue

type ExpressionValue struct {
	Left     interface{} // *MatchValue or *EExpressionValue
	Operator MathOperator
	Right    interface{} // *MatchValue or *EExpressionValue
}

func (*ExpressionValue) ExpressionDump

func (expr *ExpressionValue) ExpressionDump(w io.Writer, indent string, level int)

type MatchExpression

type MatchExpression struct {
	Operator MatchOperator
	Left     *ExpressionValue
	Right    *ExpressionValue
}

func (*MatchExpression) ExpressionDump

func (expr *MatchExpression) ExpressionDump(w io.Writer, indent string, level int)

type MatchOperator

type MatchOperator int
const (
	MatchEqual MatchOperator = iota
	MatchNotEqual
	MatchIn
	MatchNotIn
	MatchIsEmpty
	MatchIsNotEmpty
	MatchMatches
	MatchNotMatches
	MatchLower
	MatchLowerOrEqual
	MatchHigher
	MatchHigherOrEqual
)

func (MatchOperator) NotPresentDisposition

func (op MatchOperator) NotPresentDisposition() bool

NotPresentDisposition is called during evaluation when Selector fails to find a map key to determine the operator's behavior.

func (MatchOperator) String

func (op MatchOperator) String() string

type MatchValue

type MatchValue struct {
	Selector  Selector
	Type      ValueType
	Raw       string
	Converted interface{}
}

type MathOperator

type MathOperator int
const (
	MathOpValue MathOperator = iota
	MathOpPlus
	MathOpMinus
	MathOpMul
	MathOpDiv
)

func (MathOperator) String

func (op MathOperator) String() string

type Option

type Option func(*parser) Option

Option is a function that can set an option on the parser. It returns the previous setting as an Option.

func AllowInvalidUTF8

func AllowInvalidUTF8(b bool) Option

AllowInvalidUTF8 creates an Option to allow invalid UTF-8 bytes. Every invalid UTF-8 byte is treated as a utf8.RuneError (U+FFFD) by character class matchers and is matched by the any matcher. The returned matched value, c.text and c.offset are NOT affected.

The default is false.

func Entrypoint

func Entrypoint(ruleName string) Option

Entrypoint creates an Option to set the rule name to use as entrypoint. The rule name must have been specified in the -alternate-entrypoints if generating the parser with the -optimize-grammar flag, otherwise it may have been optimized out. Passing an empty string sets the entrypoint to the first rule in the grammar.

The default is to start parsing at the first rule in the grammar.

func GlobalStore

func GlobalStore(key string, value interface{}) Option

GlobalStore creates an Option to set a key to a certain value in the globalStore.

func MaxExpressions

func MaxExpressions(maxExprCnt uint64) Option

MaxExpressions creates an Option to stop parsing after the provided number of expressions have been parsed, if the value is 0 then the parser will parse for as many steps as needed (possibly an infinite number).

The default for maxExprCnt is 0.

func Recover

func Recover(b bool) Option

Recover creates an Option to set the recover flag to b. When set to true, this causes the parser to recover from panics and convert it to an error. Setting it to false can be useful while debugging to access the full stack trace.

The default is true.

type Selector

type Selector struct {
	Type SelectorType
	Path []string
}

func (Selector) String

func (sel Selector) String() string

type SelectorType

type SelectorType uint32

type Stats

type Stats struct {
	// ExprCnt counts the number of expressions processed during parsing
	// This value is compared to the maximum number of expressions allowed
	// (set by the MaxExpressions option).
	ExprCnt uint64

	// ChoiceAltCnt is used to count for each ordered choice expression,
	// which alternative is used how may times.
	// These numbers allow to optimize the order of the ordered choice expression
	// to increase the performance of the parser
	//
	// The outer key of ChoiceAltCnt is composed of the name of the rule as well
	// as the line and the column of the ordered choice.
	// The inner key of ChoiceAltCnt is the number (one-based) of the matching alternative.
	// For each alternative the number of matches are counted. If an ordered choice does not
	// match, a special counter is incremented. The name of this counter is set with
	// the parser option Statistics.
	// For an alternative to be included in ChoiceAltCnt, it has to match at least once.
	ChoiceAltCnt map[string]map[string]int
}

Stats stores some statistics, gathered during parsing

type UnaryExpression

type UnaryExpression struct {
	Operator UnaryOperator
	Operand  Expression
}

func (*UnaryExpression) ExpressionDump

func (expr *UnaryExpression) ExpressionDump(w io.Writer, indent string, level int)

type UnaryOperator

type UnaryOperator int
const (
	UnaryOpNot UnaryOperator = iota
)

func (UnaryOperator) String

func (op UnaryOperator) String() string

type ValueType

type ValueType uint32

Jump to

Keyboard shortcuts

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