Documentation
¶
Index ¶
- func IncorrectType(funcName string, expected, received interface{}) error
- func IncorrectValue(funcName string, expected, received interface{}) error
- func Parse(filename string, b []byte, opts ...Option) (interface{}, error)
- func ParseFile(filename string, opts ...Option) (i interface{}, err error)
- func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error)
- type AndX
- type Between
- type BooleanX
- type Cloner
- type DateTimeX
- type EndsWithX
- type EqualsX
- type ErrIncorrectType
- type ErrIncorrectValue
- type Expression
- type FloatX
- type GreaterThanEqualX
- type GreaterThanX
- type HasAllX
- type HasAnyX
- type HasX
- type InSliceX
- type IntegerX
- type LessThanEqualX
- type LessThanX
- type LikeX
- type MatchRegexpX
- type NotEqualsX
- type NotHasX
- type NotInSliceX
- type NotLikeX
- type NotMatchRegexpX
- type NullX
- type Option
- func AllowInvalidUTF8(b bool) Option
- func Debug(b bool) Option
- func Entrypoint(ruleName string) Option
- func GlobalStore(key string, value interface{}) Option
- func InitState(key string, value interface{}) Option
- func MaxExpressions(maxExprCnt uint64) Option
- func Memoize(b bool) Option
- func Recover(b bool) Option
- func Statistics(stats *Stats, choiceNoMatch string) Option
- type OrX
- type ParamX
- type RegexpX
- type SliceX
- type StartsWithX
- type Statement
- type Stats
- type StringX
- type Stringify
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IncorrectType ¶
func IncorrectValue ¶
Types ¶
type AndX ¶
type AndX struct {
Conjuncts []Expression
}
func And ¶
func And(expr ...Expression) *AndX
func (AndX) Equals ¶
func (e AndX) Equals(other Expression) bool
type BooleanX ¶
type BooleanX struct {
Val bool
}
func (BooleanX) Equals ¶
func (v BooleanX) Equals(other Expression) bool
type Cloner ¶
type Cloner interface {
Clone() interface{}
}
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 EqualsX ¶
type EqualsX struct {
// contains filtered or unexported fields
}
func (EqualsX) Equals ¶
func (e EqualsX) Equals(other Expression) bool
type ErrIncorrectType ¶
type ErrIncorrectType struct { FuncName string Expected interface{} Received interface{} }
func (ErrIncorrectType) Error ¶
func (e ErrIncorrectType) Error() string
type ErrIncorrectValue ¶
type ErrIncorrectValue struct { FuncName string Expected interface{} Received interface{} }
func (ErrIncorrectValue) Error ¶
func (e ErrIncorrectValue) Error() string
type Expression ¶
type Expression interface { Equals(Expression) bool String() string }
func ParseExpression ¶
func ParseExpression(data string, opts ...Option) (Expression, error)
type FloatX ¶
type FloatX struct {
Val float64
}
func (FloatX) Equals ¶
func (f FloatX) Equals(other Expression) bool
type GreaterThanEqualX ¶
type GreaterThanEqualX struct {
// contains filtered or unexported fields
}
func GreaterThanEqual ¶
func GreaterThanEqual(param *ParamX, value Value) *GreaterThanEqualX
func (GreaterThanEqualX) Equals ¶
func (s GreaterThanEqualX) Equals(other Expression) bool
func (GreaterThanEqualX) String ¶
func (s GreaterThanEqualX) String() string
type GreaterThanX ¶
type GreaterThanX struct {
// contains filtered or unexported fields
}
func GreaterThan ¶
func GreaterThan(param *ParamX, value Value) *GreaterThanX
func (GreaterThanX) Equals ¶
func (s GreaterThanX) Equals(other Expression) bool
func (GreaterThanX) String ¶
func (s GreaterThanX) String() string
type HasX ¶
type HasX struct {
// contains filtered or unexported fields
}
func (HasX) Equals ¶
func (e HasX) Equals(other Expression) bool
type IntegerX ¶
type IntegerX struct {
Val int64
}
func (IntegerX) Equals ¶
func (i IntegerX) Equals(other Expression) bool
type LessThanEqualX ¶
type LessThanEqualX struct {
// contains filtered or unexported fields
}
func LessThanEqual ¶
func LessThanEqual(param *ParamX, value Value) *LessThanEqualX
func (LessThanEqualX) Equals ¶
func (s LessThanEqualX) Equals(other Expression) bool
func (LessThanEqualX) String ¶
func (s LessThanEqualX) String() string
type LessThanX ¶
type LessThanX struct {
// contains filtered or unexported fields
}
func (LessThanX) Equals ¶
func (s LessThanX) Equals(other Expression) bool
type LikeX ¶
type LikeX struct {
// contains filtered or unexported fields
}
func (LikeX) Equals ¶
func (e LikeX) Equals(other Expression) bool
type MatchRegexpX ¶
func MatchRegexp ¶
func MatchRegexp(param *ParamX, regexp *RegexpX) *MatchRegexpX
func (MatchRegexpX) Equals ¶
func (e MatchRegexpX) Equals(other Expression) bool
func (MatchRegexpX) GetParam ¶
func (e MatchRegexpX) GetParam() *ParamX
func (MatchRegexpX) GetValue ¶
func (e MatchRegexpX) GetValue() Value
func (MatchRegexpX) String ¶
func (e MatchRegexpX) String() string
type NotEqualsX ¶
type NotEqualsX struct {
// contains filtered or unexported fields
}
func NotEquals ¶
func NotEquals(param *ParamX, value Value) *NotEqualsX
func (NotEqualsX) Equals ¶
func (e NotEqualsX) Equals(other Expression) bool
func (NotEqualsX) String ¶
func (e NotEqualsX) String() string
type NotHasX ¶
type NotHasX struct {
// contains filtered or unexported fields
}
func (NotHasX) Equals ¶
func (e NotHasX) Equals(other Expression) bool
type NotInSliceX ¶
func NotInSlice ¶
func NotInSlice(param *ParamX, slice *SliceX) *NotInSliceX
func (NotInSliceX) Equals ¶
func (e NotInSliceX) Equals(other Expression) bool
func (NotInSliceX) GetParam ¶
func (e NotInSliceX) GetParam() *ParamX
func (NotInSliceX) GetValue ¶
func (e NotInSliceX) GetValue() Value
func (NotInSliceX) String ¶
func (e NotInSliceX) String() string
type NotLikeX ¶
type NotLikeX struct {
// contains filtered or unexported fields
}
func (NotLikeX) Equals ¶
func (e NotLikeX) Equals(other Expression) bool
type NotMatchRegexpX ¶
func NotMatchRegexp ¶
func NotMatchRegexp(param *ParamX, regexp *RegexpX) *NotMatchRegexpX
func (NotMatchRegexpX) Equals ¶
func (e NotMatchRegexpX) Equals(other Expression) bool
func (NotMatchRegexpX) GetParam ¶
func (e NotMatchRegexpX) GetParam() *ParamX
func (NotMatchRegexpX) GetValue ¶
func (e NotMatchRegexpX) GetValue() Value
func (NotMatchRegexpX) String ¶
func (e NotMatchRegexpX) 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 ¶
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 OrX ¶
type OrX struct {
Disjunctions []Expression
}
func Or ¶
func Or(expr ...Expression) *OrX
func (OrX) Equals ¶
func (e OrX) Equals(other Expression) bool
type ParamX ¶
type ParamX struct {
Name string
}
func (ParamX) Equals ¶
func (p ParamX) Equals(other Expression) bool
func (ParamX) IsStringify ¶
type SliceX ¶
type SliceX struct {
Values []Value
}
func (SliceX) Equals ¶
func (e SliceX) Equals(other Expression) bool
type StartsWithX ¶
func StartsWith ¶
func StartsWith(param *ParamX, value Stringify) *StartsWithX
func (StartsWithX) Equals ¶
func (e StartsWithX) Equals(other Expression) bool
func (StartsWithX) GetParam ¶
func (e StartsWithX) GetParam() *ParamX
func (StartsWithX) GetValue ¶
func (e StartsWithX) GetValue() Value
func (StartsWithX) String ¶
func (e StartsWithX) String() string
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 StringX ¶
type StringX struct {
Val string
}
func (StringX) Equals ¶
func (s StringX) Equals(other Expression) bool
func (StringX) IsStringify ¶
type Value ¶
type Value interface { Expression Value() interface{} }