ast

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2021 License: Apache-2.0 Imports: 5 Imported by: 4

Documentation

Overview

Package ast declares the types used to represent syntax trees for Logstash configurations.

Index

Constants

View Source
const (

	// Input type plugin
	Input = iota + 1
	// Filter type plugin
	Filter
	// Output type plugin
	Output
)
View Source
const (

	// DoubleQuoted string attribute type
	DoubleQuoted = iota + 1

	// SingleQuoted string attribute type
	SingleQuoted

	// Bareword string attribute type
	Bareword
)
View Source
const (

	// Equal defines the equal operator (==)
	Equal = iota + 1

	// NotEqual defines the not equal operator (!=)
	NotEqual

	// LessOrEqual defines the less or equal operator (<=)
	LessOrEqual

	// GreaterOrEqual defines the greater or equal operator (>=)
	GreaterOrEqual

	// LessThan defines the less than operator (<)
	LessThan

	// GreaterThan defines the greater than operator (>)
	GreaterThan
)
View Source
const (

	// RegexpMatch is the regular expression match operator (=~)
	RegexpMatch = iota + 1

	// RegexpNotMatch is the regular expression not match operator (!~)
	RegexpNotMatch
)
View Source
const (

	// NoOperator is used for the first expression, which is not chained by a boolean operator
	NoOperator = iota + 1

	// And is the and boolean operator
	And

	// Or is the or boolean operator
	Or

	// Xor is the xor boolean operator
	Xor

	// Nand is the nand boolean operator
	Nand
)
View Source
const Undefined = 0

Undefined is a placeholder for all undefined values in all available types in this package.

Variables

View Source
var InvalidPos = Pos{Offset: -1}

Functions

func IsNotFoundError added in v0.4.0

func IsNotFoundError(e error) bool

IsNotFoundError returns true, if the provided error implements the NotFound interface.

func NewNotFoundError added in v0.4.0

func NewNotFoundError(err error) error

NewNotFoundError wraps an error as a not found error.

func NotFoundErrorf added in v0.4.0

func NotFoundErrorf(format string, a ...interface{}) error

NotFoundErrorf formats according to a format specifier and returns the string as a value that satisfies NotFounder.

Types

type ArrayAttribute

type ArrayAttribute struct {
	Start Pos

	Attributes    []Attribute
	Comment       CommentBlock
	FooterComment CommentBlock
	// contains filtered or unexported fields
}

A ArrayAttribute node represents a plugin attribute of type array.

func NewArrayAttribute

func NewArrayAttribute(name string, value ...Attribute) ArrayAttribute

NewArrayAttribute creates a new array attribute.

func (ArrayAttribute) CommentBlock added in v0.4.1

func (aa ArrayAttribute) CommentBlock() string

CommentBlock returns the comment of the node.

func (ArrayAttribute) Name added in v0.2.0

func (aa ArrayAttribute) Name() string

Name returns the name of the attribute.

func (ArrayAttribute) Pos added in v0.5.0

func (aa ArrayAttribute) Pos() Pos

func (ArrayAttribute) String

func (aa ArrayAttribute) String() string

String returns a string representation of a array attribute.

func (ArrayAttribute) Value

func (aa ArrayAttribute) Value() []Attribute

Value returns the value of the node.

func (ArrayAttribute) ValueString

func (aa ArrayAttribute) ValueString() string

ValueString returns the value of the node as a string representation.

type Attribute

type Attribute interface {
	Name() string
	String() string
	ValueString() string
	CommentBlock() string
	Pos() Pos
	// contains filtered or unexported methods
}

Attribute interface combines Logstash plugin attribute types.

type BoolExpression

type BoolExpression struct {
	Start Pos
	// contains filtered or unexported fields
}

A BoolExpression node represents a boolean operator.

func (*BoolExpression) BoolOperator

func (be *BoolExpression) BoolOperator() BooleanOperator

BoolOperator returns the boolean operator of the node.

func (BoolExpression) Pos added in v0.5.0

func (be BoolExpression) Pos() Pos

func (*BoolExpression) SetBoolOperator

func (be *BoolExpression) SetBoolOperator(bo BooleanOperator)

SetBoolOperator sets the boolean operator for the node.

func (BoolExpression) String

func (be BoolExpression) String() string

String returns a string representation of a boolean expression.

type BooleanOperator

type BooleanOperator struct {
	Op    int
	Start Pos
}

A BooleanOperator represents a boolean operator.

func (BooleanOperator) Pos added in v0.5.0

func (bo BooleanOperator) Pos() Pos

func (BooleanOperator) String

func (be BooleanOperator) String() string

String returns a string representation of a boolean operator.

type Branch

type Branch struct {
	IfBlock     IfBlock
	ElseIfBlock []ElseIfBlock
	ElseBlock   ElseBlock
}

A Branch node represents a conditional branch within a Logstash configuration.

func NewBranch

func NewBranch(ifBlock IfBlock, elseBlock ElseBlock, elseIfBlock ...ElseIfBlock) Branch

NewBranch creates a new branch. Arguments for elseBlock and elseIfBlock are in the wrong order from logically point of view. This is due to the variadic nature of the elseIfBlock argument.

func (Branch) Pos added in v0.5.0

func (b Branch) Pos() Pos

func (Branch) String

func (b Branch) String() string

String returns a string representation of a branch.

type BranchOrPlugin

type BranchOrPlugin interface {
	Pos() Pos
	// contains filtered or unexported methods
}

BranchOrPlugin interface combines Logstash configuration conditional branches and plugins.

type Comment added in v0.4.1

type Comment struct {
	SpaceBefore bool
	SpaceAfter  bool
	// contains filtered or unexported fields
}

func NewComment added in v0.4.1

func NewComment(comment string, space bool) Comment

func (Comment) String added in v0.4.1

func (c Comment) String() string

type CommentBlock added in v0.4.1

type CommentBlock []Comment

func NewCommentBlock added in v0.4.1

func NewCommentBlock(comments ...Comment) CommentBlock

func (CommentBlock) String added in v0.4.1

func (cb CommentBlock) String() string

type Commentable added in v0.4.1

type Commentable interface {
	SetComment(cb CommentBlock)
}

A Commentable node is an ast node, which accepts comments.

type CompareExpression

type CompareExpression struct {
	Start Pos
	*BoolExpression
	LValue          Rvalue
	CompareOperator CompareOperator
	RValue          Rvalue
}

A CompareExpression node represents a expression, which compares lvalue and rvalue based on the comparison operator.

func NewCompareExpression

func NewCompareExpression(boolOperator BooleanOperator, lvalue Rvalue, compareOperator CompareOperator, rvalue Rvalue) CompareExpression

NewCompareExpression creates a new compare expression.

func (CompareExpression) Pos added in v0.5.0

func (ce CompareExpression) Pos() Pos

func (CompareExpression) String

func (ce CompareExpression) String() string

String returns a string representation of a compare expression.

type CompareOperator

type CompareOperator struct {
	Op    int
	Start Pos
}

A CompareOperator represents the comparison operator, used to compare two values.

func (CompareOperator) Pos added in v0.5.0

func (co CompareOperator) Pos() Pos

func (CompareOperator) String

func (co CompareOperator) String() string

String returns a string representation of a compare operator.

type Condition

type Condition struct {
	Expression []Expression
}

A Condition node represents a condition used by if- or else-if-blocks.

func NewCondition

func NewCondition(expression ...Expression) Condition

NewCondition creates a new condition.

func (Condition) Pos added in v0.5.0

func (c Condition) Pos() Pos

func (Condition) String

func (c Condition) String() string

String returns a string representation of a condition.

type ConditionExpression

type ConditionExpression struct {
	Start Pos
	*BoolExpression
	Condition Condition
}

A ConditionExpression node represents an Expression, which is enclosed in parentheses.

func NewConditionExpression

func NewConditionExpression(boolOperator BooleanOperator, condition Condition) ConditionExpression

NewConditionExpression creates a new condition expression.

func (ConditionExpression) Pos added in v0.5.0

func (ce ConditionExpression) Pos() Pos

func (ConditionExpression) String

func (ce ConditionExpression) String() string

String returns a string representation of a condition expression.

type Config

type Config struct {
	Input         []PluginSection
	Filter        []PluginSection
	Output        []PluginSection
	FooterComment CommentBlock
	Warnings      []string
}

A Config node represents the root node of a Logstash configuration.

func NewConfig

func NewConfig(input, filter, output []PluginSection) Config

NewConfig creates a new Logstash config.

func (Config) Pos added in v0.5.0

func (c Config) Pos() Pos

func (Config) String

func (c Config) String() string

String returns a string representation of a Logstash configuration.

type ElseBlock

type ElseBlock struct {
	Start         Pos
	Block         []BranchOrPlugin
	Comment       CommentBlock
	FooterComment CommentBlock
}

A ElseBlock node represents a else-block of a Branch.

func NewElseBlock

func NewElseBlock(block ...BranchOrPlugin) ElseBlock

NewElseBlock creates a new else-block

func (ElseBlock) Pos added in v0.5.0

func (eb ElseBlock) Pos() Pos

func (ElseBlock) String

func (eb ElseBlock) String() string

String returns a string representation of an else block.

type ElseIfBlock

type ElseIfBlock struct {
	Start         Pos
	Condition     Condition
	Block         []BranchOrPlugin
	Comment       CommentBlock
	FooterComment CommentBlock
}

A ElseIfBlock node represents an else-if-block of a Branch.

func NewElseIfBlock

func NewElseIfBlock(condition Condition, block ...BranchOrPlugin) ElseIfBlock

NewElseIfBlock creates a new else-if-block of a Branch.

func (ElseIfBlock) Pos added in v0.5.0

func (eib ElseIfBlock) Pos() Pos

func (ElseIfBlock) String

func (eib ElseIfBlock) String() string

String returns a string representation of an else if block.

type Expression

type Expression interface {
	Pos() Pos
	BoolOperator() BooleanOperator
	SetBoolOperator(BooleanOperator)
	// contains filtered or unexported methods
}

An Expression node defines an expression. An Expression is chainable with a preceding Expression by the the boolean operator.

type HashAttribute

type HashAttribute struct {
	Start Pos

	Entries       []HashEntry
	Comment       CommentBlock
	FooterComment CommentBlock
	// contains filtered or unexported fields
}

A HashAttribute node represents a plugin attribute of type hash.

func NewHashAttribute

func NewHashAttribute(name string, entries ...HashEntry) HashAttribute

NewHashAttribute creates a new hash attribute.

func (HashAttribute) CommentBlock added in v0.4.1

func (ha HashAttribute) CommentBlock() string

CommentBlock returns the comment of the node.

func (HashAttribute) Name added in v0.2.0

func (ha HashAttribute) Name() string

Name returns the name of the attribute.

func (HashAttribute) Pos added in v0.5.0

func (ha HashAttribute) Pos() Pos

func (HashAttribute) String

func (ha HashAttribute) String() string

String returns a string representation of a hash attribute.

func (HashAttribute) Value

func (ha HashAttribute) Value() []HashEntry

Value returns the value of the node.

func (HashAttribute) ValueString

func (ha HashAttribute) ValueString() string

ValueString returns the value of the node as a string representation.

type HashEntry

type HashEntry struct {
	Start   Pos
	Key     HashEntryKey
	Value   Attribute
	Comment CommentBlock
}

A HashEntry node defines a hash entry within a hash attribute.

func NewHashEntry

func NewHashEntry(name HashEntryKey, value Attribute) HashEntry

NewHashEntry creates a new hash entry for a hash attribute.

func (HashEntry) Name added in v0.2.0

func (he HashEntry) Name() string

Name returns the name of the attribute.

func (HashEntry) Pos added in v0.5.0

func (he HashEntry) Pos() Pos

func (HashEntry) String

func (he HashEntry) String() string

String returns a string representation of a hash entry.

func (HashEntry) ValueString

func (he HashEntry) ValueString() string

ValueString returns the value of the node as a string representation.

type HashEntryKey added in v0.4.5

type HashEntryKey interface {
	Pos() Pos
	ValueString() string
	// contains filtered or unexported methods
}

type IfBlock

type IfBlock struct {
	Start         Pos
	Condition     Condition
	Block         []BranchOrPlugin
	Comment       CommentBlock
	FooterComment CommentBlock
}

A IfBlock node represents an if-block of a Branch.

func NewIfBlock

func NewIfBlock(condition Condition, block ...BranchOrPlugin) IfBlock

NewIfBlock creates a new if-block.

func (IfBlock) Pos added in v0.5.0

func (ib IfBlock) Pos() Pos

func (IfBlock) String

func (ib IfBlock) String() string

String returns a string representation of an if-block.

type InExpression

type InExpression struct {
	Start Pos
	*BoolExpression
	LValue Rvalue
	RValue Rvalue
}

An InExpression node represents an in expression.

func NewInExpression

func NewInExpression(boolOperator BooleanOperator, lvalue Rvalue, rvalue Rvalue) InExpression

NewInExpression creates a new in expression.

func (InExpression) Pos added in v0.5.0

func (ie InExpression) Pos() Pos

func (InExpression) String

func (ie InExpression) String() string

String returns a string representation of an in expression.

type NegativeConditionExpression

type NegativeConditionExpression struct {
	Start Pos
	*BoolExpression
	Condition Condition
}

A NegativeConditionExpression node represents an Expression within parentheses, which is negated.

func NewNegativeConditionExpression

func NewNegativeConditionExpression(boolOperator BooleanOperator, condition Condition) NegativeConditionExpression

NewNegativeConditionExpression creates a new negative condition expression.

func (NegativeConditionExpression) Pos added in v0.5.0

func (NegativeConditionExpression) String

func (nc NegativeConditionExpression) String() string

String returns a string representation of a negative condition expression.

type NegativeSelectorExpression

type NegativeSelectorExpression struct {
	Start Pos
	*BoolExpression
	Selector Selector
}

A NegativeSelectorExpression node represents a field selector expression, which is negated.

func NewNegativeSelectorExpression

func NewNegativeSelectorExpression(boolOperator BooleanOperator, selector Selector) NegativeSelectorExpression

NewNegativeSelectorExpression creates a new negative selector expression.

func (NegativeSelectorExpression) Pos added in v0.5.0

func (NegativeSelectorExpression) String

func (ns NegativeSelectorExpression) String() string

String returns a string representation of a negative selector expression.

type Node added in v0.5.0

type Node interface {
	Pos() Pos
}

type NotFounder added in v0.4.0

type NotFounder interface {
	Error() string
	NotFound()
}

NotFounder interface is implemented by errors, that indicate that a record is not found.

type NotInExpression

type NotInExpression struct {
	Start Pos
	*BoolExpression
	RValue Rvalue
	LValue Rvalue
}

A NotInExpression node defines a not in expression.

func NewNotInExpression

func NewNotInExpression(boolOperator BooleanOperator, lvalue Rvalue, rvalue Rvalue) NotInExpression

NewNotInExpression creates a new not in expression.

func (NotInExpression) Pos added in v0.5.0

func (nie NotInExpression) Pos() Pos

func (NotInExpression) String

func (nie NotInExpression) String() string

String returns a string representation of a not in expression.

type NumberAttribute

type NumberAttribute struct {
	Start Pos

	Comment CommentBlock
	// contains filtered or unexported fields
}

A NumberAttribute node represents a plugin attribute of type number.

func NewNumberAttribute

func NewNumberAttribute(name string, value float64) NumberAttribute

NewNumberAttribute creates a new number attribute.

func (NumberAttribute) CommentBlock added in v0.4.1

func (na NumberAttribute) CommentBlock() string

CommentBlock returns the comment of the node.

func (NumberAttribute) Name added in v0.2.0

func (na NumberAttribute) Name() string

Name returns the name of the attribute.

func (NumberAttribute) Pos added in v0.5.0

func (na NumberAttribute) Pos() Pos

func (NumberAttribute) String

func (na NumberAttribute) String() string

String returns a string representation of a number attribute.

func (NumberAttribute) Value

func (na NumberAttribute) Value() float64

Value returns the value of the node.

func (NumberAttribute) ValueString

func (na NumberAttribute) ValueString() string

ValueString returns the value of the node as a string representation.

type Plugin

type Plugin struct {
	Start Pos

	Attributes    []Attribute
	Comment       CommentBlock
	FooterComment CommentBlock
	// contains filtered or unexported fields
}

A Plugin node represents a Logstash plugin.

func NewPlugin

func NewPlugin(name string, attributes ...Attribute) Plugin

NewPlugin creates a new plugin.

func (Plugin) ID added in v0.4.0

func (p Plugin) ID() (string, error)

ID returns the id of a Logstash plugin. The id attribute is one of the common options, that is optionally available on every Logstash plugin. In generall, it is highly recommended for a Logstash plugin to have an id. If the ID attribute is not present, an error is returned, who implements the NotFounder interface.

func (Plugin) Name added in v0.2.0

func (p Plugin) Name() string

Name returns the name of the attribute.

func (Plugin) Pos added in v0.5.0

func (p Plugin) Pos() Pos

func (Plugin) String

func (p Plugin) String() string

String returns a string representation of a plugin.

type PluginAttribute

type PluginAttribute struct {
	Start Pos

	Comment CommentBlock
	// contains filtered or unexported fields
}

A PluginAttribute node represents a plugin attribute of type plugin.

func NewPluginAttribute

func NewPluginAttribute(name string, value Plugin) PluginAttribute

NewPluginAttribute creates a new plugin attribute.

func (PluginAttribute) CommentBlock added in v0.4.1

func (pa PluginAttribute) CommentBlock() string

CommentBlock returns the comment of the node.

func (PluginAttribute) Name added in v0.2.0

func (pa PluginAttribute) Name() string

Name returns the name of the attribute.

func (PluginAttribute) Pos added in v0.5.0

func (pa PluginAttribute) Pos() Pos

func (PluginAttribute) String

func (pa PluginAttribute) String() string

String returns a string representation of a plugin attribute.

func (PluginAttribute) ValueString

func (pa PluginAttribute) ValueString() string

ValueString returns the value of the node as a string representation.

type PluginSection

type PluginSection struct {
	Start           Pos
	PluginType      PluginType
	BranchOrPlugins []BranchOrPlugin
	CommentBlock    CommentBlock
	FooterComment   CommentBlock
}

A PluginSection node defines the configuration section with branches or plugins.

func NewPluginSection

func NewPluginSection(pt PluginType, bop ...BranchOrPlugin) PluginSection

NewPluginSection creates a new plugin section.

func NewPluginSections

func NewPluginSections(pt PluginType, bop ...BranchOrPlugin) []PluginSection

NewPluginSections creates an array of plugin sections.

func (PluginSection) Pos added in v0.5.0

func (ps PluginSection) Pos() Pos

func (PluginSection) String

func (ps PluginSection) String() string

String returns a string representation of a plugin section.

type PluginType

type PluginType int

PluginType defines the type of a Logstash plugin, which is one of: Input, Filter or Output.

func (PluginType) String

func (pt PluginType) String() string

String returns a string representation of a plugin type.

type Pos added in v0.5.0

type Pos struct {
	Line   int
	Column int
	Offset int
}

func (Pos) String added in v0.5.0

func (p Pos) String() string

type Regexp

type Regexp struct {
	Start  Pos
	Regexp string
}

A Regexp node represents a regular expression.

func NewRegexp

func NewRegexp(regexp string) Regexp

NewRegexp creates a new Regexp.

func (Regexp) Pos added in v0.5.0

func (r Regexp) Pos() Pos

func (Regexp) String

func (r Regexp) String() string

String returns a string representation of a regexp.

func (Regexp) ValueString

func (r Regexp) ValueString() string

ValueString returns the value of the node as a string representation.

type RegexpExpression

type RegexpExpression struct {
	Start Pos
	*BoolExpression
	LValue         Rvalue
	RegexpOperator RegexpOperator
	RValue         StringOrRegexp
}

A RegexpExpression node defines a regular expression node.

func NewRegexpExpression

func NewRegexpExpression(boolOperator BooleanOperator, lvalue Rvalue, regexpOperator RegexpOperator, rvalue StringOrRegexp) RegexpExpression

NewRegexpExpression creates a new regexp (regular expression) expression.

func (RegexpExpression) Pos added in v0.5.0

func (re RegexpExpression) Pos() Pos

func (RegexpExpression) String

func (re RegexpExpression) String() string

String returns a string representation of a regexp expression.

type RegexpOperator

type RegexpOperator struct {
	Op    int
	Start Pos
}

A RegexpOperator is an operator, used to compare a regular expression with an other value.

func (RegexpOperator) Pos added in v0.5.0

func (ro RegexpOperator) Pos() Pos

func (RegexpOperator) String

func (ro RegexpOperator) String() string

String returns a string representation of a regexp operator.

type Rvalue

type Rvalue interface {
	Pos() Pos
	String() string
	ValueString() string
	// contains filtered or unexported methods
}

A Rvalue node represents an right (or in some cases also an left) side value of an expression.

type RvalueExpression

type RvalueExpression struct {
	Start Pos
	*BoolExpression
	RValue Rvalue
}

A RvalueExpression node defines an expression consisting only of a Rvalue.

func NewRvalueExpression

func NewRvalueExpression(boolOperator BooleanOperator, rvalue Rvalue) RvalueExpression

NewRvalueExpression creates a new rvalue expression.

func (RvalueExpression) Pos added in v0.5.0

func (re RvalueExpression) Pos() Pos

func (RvalueExpression) String

func (re RvalueExpression) String() string

String returns a string representation of a rvalue expression.

type Selector

type Selector struct {
	Start    Pos
	Elements []SelectorElement
}

A Selector node represents a field selector.

func NewSelector

func NewSelector(elements []SelectorElement) Selector

NewSelector creates a new Selector.

func NewSelectorFromNames

func NewSelectorFromNames(names ...string) Selector

NewSelectorFromNames creates a new Selector form a slice of field names.

func (Selector) Pos added in v0.5.0

func (s Selector) Pos() Pos

func (Selector) String

func (s Selector) String() string

String returns a string representation of a selector.

func (Selector) ValueString

func (s Selector) ValueString() string

ValueString returns the value of the node as a string representation.

type SelectorElement

type SelectorElement struct {
	Start Pos
	// contains filtered or unexported fields
}

A SelectorElement node defines a selector element.

func NewSelectorElement

func NewSelectorElement(name string) SelectorElement

NewSelectorElement creates a new selector element.

func (SelectorElement) Pos added in v0.5.0

func (se SelectorElement) Pos() Pos

func (SelectorElement) String

func (se SelectorElement) String() string

String returns a string representation of a selector element.

type StringAttribute

type StringAttribute struct {
	Start Pos

	Comment CommentBlock
	// contains filtered or unexported fields
}

StringAttribute is a plugin attribute of type string.

func NewStringAttribute

func NewStringAttribute(name, value string, sat StringAttributeType) StringAttribute

NewStringAttribute creates a new plugin attribute of type string.

func (StringAttribute) CommentBlock added in v0.4.1

func (sa StringAttribute) CommentBlock() string

CommentBlock returns the comment of the node.

func (StringAttribute) Name added in v0.2.0

func (sa StringAttribute) Name() string

Name returns the name of the attribute.

func (StringAttribute) Pos added in v0.5.0

func (sa StringAttribute) Pos() Pos

func (StringAttribute) String

func (sa StringAttribute) String() string

String returns a string representation of a string attribute.

func (StringAttribute) StringAttributeType

func (sa StringAttribute) StringAttributeType() StringAttributeType

StringAttributeType returns the string attribute type.

func (StringAttribute) Value

func (sa StringAttribute) Value() string

Value returns the value of the node.

func (StringAttribute) ValueString

func (sa StringAttribute) ValueString() string

ValueString returns the value of the node as a string representation.

type StringAttributeType

type StringAttributeType int

StringAttributeType defines the string format type of a string attribute.

func (StringAttributeType) String

func (sat StringAttributeType) String() string

String returns a string representation of a string attribute type.

type StringOrRegexp

type StringOrRegexp interface {
	Pos() Pos
	String() string
	ValueString() string
	// contains filtered or unexported methods
}

A StringOrRegexp node is a string attribute node or a regexp node.

type Whitespace added in v0.4.1

type Whitespace struct{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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