Documentation ¶
Index ¶
- func Evaluate[T any](expression Expression, context *c.Context) (T, error)
- func EvaluatePipeout[T PipeOutInstance](a T, context *c.Context, writer OutputWriter) (any, error)
- func EvaluateToString(expression Expression, context *c.Context) (string, error)
- func Execute(filePath string, context *c.Context, code []byte) (any, error)
- func MakeContext(locals *c.Locals, builtIn c.BuiltIn, system c.System) *c.Context
- func MakeDefaultBuiltIn() c.BuiltIn
- func Parse(filename string, b []byte, opts ...Option) (any, error)
- func ParseFile(filename string, opts ...Option) (i any, err error)
- func ParseReader(filename string, r io.Reader, opts ...Option) (any, error)
- type Add
- type Assign
- type BindedLambda
- type Block
- type Call
- type Cloner
- type Condition
- type Constant
- type Each
- type Equal
- type Expression
- func MakeAdd(l Expression, r Expression) Expression
- func MakeCondition(c Expression, t Expression, f Expression) Expression
- func MakeConstant(value any) Expression
- func MakeEach(l Expression, b Expression) Expression
- func MakeEqual(l Expression, r Expression) Expression
- func MakeNot(s Expression) Expression
- func MakePiped[T PipedInstance, U PipedRef[T]](from Expression, to Expression) Expression
- type ExpressionList
- type ExpressionStore
- type Expressions
- type FormatData
- type IdentifierList
- type Include
- type Invoke
- type Lambda
- type Literal
- type LiteralList
- type Member
- type NamedExpression
- type NamedExpressionList
- type Not
- type Option
- func AllowInvalidUTF8(b bool) Option
- func Debug(b bool) Option
- func Entrypoint(ruleName string) Option
- func GlobalStore(key string, value any) Option
- func InitState(key string, value any) Option
- func MaxExpressions(maxExprCnt uint64) Option
- func Memoize(b bool) Option
- func Recover(b bool) Option
- func Statistics(stats *Stats, choiceNoMatch string) Option
- type OutputCapture
- type OutputWriter
- type ParseData
- type ParsedString
- type Pipe
- type PipeAppend
- type PipeIn
- type PipeOut
- type PipeOutInstance
- type Piped
- type PipedInstance
- type PipedRef
- type PointerValue
- type Ref
- type Reference
- type Stats
- type StoreAccess
- type StoreReference
- type Template
- type Value
- type Write
- type WriteLn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Evaluate ¶ added in v0.0.2
func Evaluate[T any](expression Expression, context *c.Context) (T, error)
func EvaluatePipeout ¶ added in v0.4.1
func EvaluatePipeout[T PipeOutInstance](a T, context *c.Context, writer OutputWriter) (any, error)
func EvaluateToString ¶ added in v0.1.1
func EvaluateToString(expression Expression, context *c.Context) (string, error)
func MakeContext ¶
func MakeDefaultBuiltIn ¶
Types ¶
type Add ¶ added in v0.3.6
type Add struct { Left Expression Right Expression }
type Assign ¶
type Assign struct { Store Expression Value Expression }
type BindedLambda ¶ added in v0.3.11
func (BindedLambda) Evaluate ¶ added in v0.3.11
func (a BindedLambda) Evaluate(context *c.Context) (any, error)
func (BindedLambda) String ¶ added in v0.3.11
func (a BindedLambda) String() string
type Block ¶
type Block []Expression
type Call ¶
type Call struct { Reference Reference Arguments NamedExpressionList }
type Cloner ¶
type Cloner interface {
Clone() any
}
Cloner is implemented by any value that has a Clone method, which returns a copy of the value. This is mainly used for types which are not passed by value (e.g map, slice, chan) or structs that contain such types.
This is used in conjunction with the global state feature to create proper copies of the state to allow the parser to properly restore the state in the case of backtracking.
type Condition ¶
type Condition struct { Condition Expression True Expression False Expression }
type Constant ¶ added in v0.0.2
type Constant struct {
Value any
}
type Each ¶
type Each struct { List Expression Body Expression }
type Equal ¶
type Equal struct { Left Expression Right Expression }
type Expression ¶
func MakeAdd ¶ added in v0.3.6
func MakeAdd(l Expression, r Expression) Expression
func MakeCondition ¶
func MakeCondition(c Expression, t Expression, f Expression) Expression
func MakeConstant ¶ added in v0.3.1
func MakeConstant(value any) Expression
func MakeEach ¶
func MakeEach(l Expression, b Expression) Expression
func MakeEqual ¶
func MakeEqual(l Expression, r Expression) Expression
func MakeNot ¶
func MakeNot(s Expression) Expression
func MakePiped ¶ added in v0.4.1
func MakePiped[T PipedInstance, U PipedRef[T]](from Expression, to Expression) Expression
type ExpressionList ¶
type ExpressionList []Expression
func (ExpressionList) String ¶
func (a ExpressionList) String() string
type ExpressionStore ¶ added in v0.4.4
func MakeExpressionStore ¶ added in v0.4.4
func MakeExpressionStore(a NamedExpressionList) (ExpressionStore, error)
func (ExpressionStore) Evaluate ¶ added in v0.4.4
func (a ExpressionStore) Evaluate(context *c.Context) (any, error)
func (ExpressionStore) String ¶ added in v0.4.4
func (a ExpressionStore) String() string
type Expressions ¶
type Expressions []Expression
func (Expressions) String ¶
func (a Expressions) String() string
type FormatData ¶ added in v0.0.2
type FormatData struct { Format Expression Data Expression }
func (FormatData) Evaluate ¶ added in v0.0.2
func (a FormatData) Evaluate(context *c.Context) (any, error)
func (FormatData) String ¶ added in v0.0.2
func (v FormatData) String() string
type IdentifierList ¶
type IdentifierList struct {
Identifiers []string
}
func (IdentifierList) String ¶
func (a IdentifierList) String() string
type Include ¶
type Include struct {
FileName Expression
}
type Invoke ¶
type Invoke struct {
Expressions Expressions
}
type Lambda ¶
type Lambda struct { Arguments IdentifierList Body Expression }
type LiteralList ¶
type LiteralList []Literal
func MakeLiteralList ¶
func MakeLiteralList(s []string) LiteralList
func (LiteralList) String ¶
func (v LiteralList) String() string
type NamedExpression ¶ added in v0.4.2
type NamedExpression c.KeyValue[string, Expression]
func (NamedExpression) Evaluate ¶ added in v0.4.2
func (a NamedExpression) Evaluate(context *c.Context) (any, error)
func (NamedExpression) String ¶ added in v0.4.2
func (a NamedExpression) String() string
type NamedExpressionList ¶ added in v0.4.2
type NamedExpressionList []NamedExpression
func (NamedExpressionList) Evaluate ¶ added in v0.4.2
func (a NamedExpressionList) Evaluate(context *c.Context) (any, error)
func (NamedExpressionList) String ¶ added in v0.4.2
func (a NamedExpressionList) String() string
type Not ¶
type Not struct {
Expression Expression
}
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 ¶
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 Debug ¶
Debug creates an Option to set the debug flag to b. When set to true, debugging information is printed to stdout while parsing.
The default is false.
func Entrypoint ¶
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 ¶
GlobalStore creates an Option to set a key to a certain value in the globalStore.
func InitState ¶
InitState creates an Option to set a key to a certain value in the global "state" store.
func MaxExpressions ¶
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 Memoize ¶
Memoize creates an Option to set the memoize flag to b. When set to true, the parser will cache all results so each expression is evaluated only once. This guarantees linear parsing time even for pathological cases, at the expense of more memory and slower times for typical cases.
The default is false.
func Recover ¶
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.
func Statistics ¶
Statistics adds a user provided Stats struct to the parser to allow the user to process the results after the parsing has finished. Also the key for the "no match" counter is set.
Example usage:
input := "input" stats := Stats{} _, err := Parse("input-file", []byte(input), Statistics(&stats, "no match")) if err != nil { log.Panicln(err) } b, err := json.MarshalIndent(stats.ChoiceAltCnt, "", " ") if err != nil { log.Panicln(err) } fmt.Println(string(b))
type OutputCapture ¶ added in v0.4.3
type OutputCapture Expressions
func (OutputCapture) Evaluate ¶ added in v0.4.3
func (a OutputCapture) Evaluate(context *c.Context) (any, error)
func (OutputCapture) String ¶ added in v0.4.3
func (a OutputCapture) String() string
type OutputWriter ¶ added in v0.4.1
func Writer ¶ added in v0.4.1
func Writer(mode int) OutputWriter
type ParseData ¶ added in v0.0.2
type ParseData struct { Format Expression Data Expression }
type ParsedString ¶
func MakeParsedString ¶
func MakeParsedString(quote string, body string) ParsedString
func (ParsedString) String ¶
func (a ParsedString) String() string
func (ParsedString) Unquote ¶
func (a ParsedString) Unquote() string
type Pipe ¶ added in v0.3.5
type Pipe struct {
// contains filtered or unexported fields
}
func (*Pipe) From ¶ added in v0.3.5
func (a *Pipe) From() Ref[Expression]
func (*Pipe) To ¶ added in v0.3.5
func (a *Pipe) To() Ref[Expression]
type PipeAppend ¶ added in v0.4.1
type PipeAppend Pipe
func (PipeAppend) Evaluate ¶ added in v0.4.1
func (a PipeAppend) Evaluate(context *c.Context) (any, error)
func (*PipeAppend) From ¶ added in v0.4.1
func (a *PipeAppend) From() Ref[Expression]
func (PipeAppend) String ¶ added in v0.4.1
func (a PipeAppend) String() string
func (*PipeAppend) To ¶ added in v0.4.1
func (a *PipeAppend) To() Ref[Expression]
type PipeIn ¶ added in v0.4.1
type PipeIn Pipe
func (*PipeIn) From ¶ added in v0.4.1
func (a *PipeIn) From() Ref[Expression]
func (*PipeIn) To ¶ added in v0.4.1
func (a *PipeIn) To() Ref[Expression]
type PipeOut ¶ added in v0.4.1
type PipeOut Pipe
func (*PipeOut) From ¶ added in v0.4.1
func (a *PipeOut) From() Ref[Expression]
func (*PipeOut) To ¶ added in v0.4.1
func (a *PipeOut) To() Ref[Expression]
type PipeOutInstance ¶ added in v0.4.1
type PipeOutInstance interface { *PipeOut | *PipeAppend Piped }
type Piped ¶ added in v0.4.1
type Piped interface { From() Ref[Expression] To() Ref[Expression] }
type PipedInstance ¶ added in v0.4.1
type PipedInstance interface { Pipe | PipeIn | PipeOut | PipeAppend Expression }
type PointerValue ¶ added in v0.4.1
type PointerValue[T any] struct { // contains filtered or unexported fields }
func MakeRef ¶ added in v0.4.1
func MakeRef[T any](v *T) *PointerValue[T]
func (*PointerValue[T]) Get ¶ added in v0.4.1
func (a *PointerValue[T]) Get() *T
func (*PointerValue[T]) Set ¶ added in v0.4.1
func (a *PointerValue[T]) Set(v *T) *T
type Reference ¶
type Reference struct {
Expression Expression
}
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 StoreAccess ¶
type StoreAccess struct { Reference Expression Index Expression }
func (StoreAccess) String ¶
func (a StoreAccess) String() string
type StoreReference ¶
func (StoreReference) Get ¶
func (a StoreReference) Get() any
func (StoreReference) Set ¶
func (a StoreReference) Set(v any) any
type Template ¶ added in v0.1.1
type Template struct { Store StoreAccess Arguments IdentifierList Value Expression Text string }
func MakeTemplate ¶ added in v0.1.1
func MakeTemplate(store StoreAccess, args IdentifierList, body string) Template
type Write ¶
type Write struct {
Expression Expressions
}
Source Files ¶
- Add.go
- Assign.go
- Block.go
- BuiltIn.go
- Call.go
- Condition.go
- Constant.go
- Context.go
- Each.go
- Equal.go
- EvaluatePipeout.go
- Expression.go
- ExpressionList.go
- Expressions.go
- FormatData.go
- IdentifierList.go
- Include.go
- Interpreter.go
- Invoke.go
- Lambda.go
- Literal.go
- LiteralList.go
- Member.go
- NamedExpressionList.go
- Not.go
- OutputCapture.go
- ParseData.go
- ParsedString.go
- Pipe.go
- PipeAppend.go
- PipeIn.go
- PipeOut.go
- Piped.go
- Ref.go
- Reference.go
- Store.go
- StoreAccess.go
- Template.go
- Write.go
- funcs.go
- grammar.go
- parser.go