Documentation ¶
Index ¶
- Constants
- Variables
- func FindFunctionCalls(nodes ...Node) []string
- func FindReferenceVariables(nodes ...Node) []string
- func Format(n Node) string
- func IsCompOperator(typ TokenType) bool
- func IsExprOperator(typ TokenType) bool
- func IsLogicalOperator(typ TokenType) bool
- func IsMathOperator(typ TokenType) bool
- func ZeroValue(t ValueType) interface{}
- type BinaryNode
- func (p BinaryNode) Char() int
- func (n *BinaryNode) Equal(o interface{}) bool
- func (n *BinaryNode) Format(buf *bytes.Buffer, indent string, onNewLine bool)
- func (p BinaryNode) Line() int
- func (p BinaryNode) Position() int
- func (n *BinaryNode) SetComment(c *CommentNode)
- func (n *BinaryNode) String() string
- type BoolNode
- type ChainNode
- type CommentNode
- func (p CommentNode) Char() int
- func (n *CommentNode) CommentString() string
- func (n *CommentNode) Equal(o interface{}) bool
- func (n *CommentNode) Format(buf *bytes.Buffer, indent string, onNewLine bool)
- func (p CommentNode) Line() int
- func (p CommentNode) Position() int
- func (n *CommentNode) String() string
- type DeclarationNode
- func (p DeclarationNode) Char() int
- func (n *DeclarationNode) Equal(o interface{}) bool
- func (n *DeclarationNode) Format(buf *bytes.Buffer, indent string, onNewLine bool)
- func (p DeclarationNode) Line() int
- func (p DeclarationNode) Position() int
- func (n *DeclarationNode) SetComment(c *CommentNode)
- func (n *DeclarationNode) String() string
- type DurationNode
- func (p DurationNode) Char() int
- func (n *DurationNode) Equal(o interface{}) bool
- func (n *DurationNode) Format(buf *bytes.Buffer, indent string, onNewLine bool)
- func (p DurationNode) Line() int
- func (p DurationNode) Position() int
- func (n *DurationNode) SetComment(c *CommentNode)
- func (n *DurationNode) String() string
- type FuncType
- type FunctionNode
- func (p FunctionNode) Char() int
- func (n *FunctionNode) Equal(o interface{}) bool
- func (n *FunctionNode) Format(buf *bytes.Buffer, indent string, onNewLine bool)
- func (p FunctionNode) Line() int
- func (p FunctionNode) Position() int
- func (n *FunctionNode) SetComment(c *CommentNode)
- func (n *FunctionNode) String() string
- type IdentifierNode
- func (p IdentifierNode) Char() int
- func (n *IdentifierNode) Equal(o interface{}) bool
- func (n *IdentifierNode) Format(buf *bytes.Buffer, indent string, onNewLine bool)
- func (p IdentifierNode) Line() int
- func (p IdentifierNode) Position() int
- func (n *IdentifierNode) SetComment(c *CommentNode)
- func (n *IdentifierNode) String() string
- type LambdaNode
- func (p LambdaNode) Char() int
- func (n *LambdaNode) Equal(o interface{}) bool
- func (n *LambdaNode) ExpressionString() string
- func (n *LambdaNode) Format(buf *bytes.Buffer, indent string, onNewLine bool)
- func (p LambdaNode) Line() int
- func (p LambdaNode) Position() int
- func (n *LambdaNode) SetComment(c *CommentNode)
- func (n *LambdaNode) String() string
- type ListNode
- type Missing
- type Node
- type NumberNode
- func (p NumberNode) Char() int
- func (n *NumberNode) Equal(o interface{}) bool
- func (n *NumberNode) Format(buf *bytes.Buffer, indent string, onNewLine bool)
- func (p NumberNode) Line() int
- func (p NumberNode) Position() int
- func (n *NumberNode) SetComment(c *CommentNode)
- func (n *NumberNode) String() string
- type Position
- type ProgramNode
- func (n *ProgramNode) Add(node Node)
- func (p ProgramNode) Char() int
- func (n *ProgramNode) Equal(o interface{}) bool
- func (n *ProgramNode) Format(buf *bytes.Buffer, indent string, onNewLine bool)
- func (p ProgramNode) Line() int
- func (p ProgramNode) Position() int
- func (n *ProgramNode) String() string
- type ReferenceNode
- func (p ReferenceNode) Char() int
- func (n *ReferenceNode) Equal(o interface{}) bool
- func (n *ReferenceNode) Format(buf *bytes.Buffer, indent string, onNewLine bool)
- func (p ReferenceNode) Line() int
- func (p ReferenceNode) Position() int
- func (n *ReferenceNode) SetComment(c *CommentNode)
- func (n *ReferenceNode) String() string
- type RegexNode
- type StarNode
- type StringNode
- func (p StringNode) Char() int
- func (n *StringNode) Equal(o interface{}) bool
- func (n *StringNode) Format(buf *bytes.Buffer, indent string, onNewLine bool)
- func (p StringNode) Line() int
- func (p StringNode) Position() int
- func (n *StringNode) SetComment(c *CommentNode)
- func (n *StringNode) String() string
- type TokenType
- type TypeDeclarationNode
- func (p TypeDeclarationNode) Char() int
- func (n *TypeDeclarationNode) Equal(o interface{}) bool
- func (n *TypeDeclarationNode) Format(buf *bytes.Buffer, indent string, onNewLine bool)
- func (p TypeDeclarationNode) Line() int
- func (p TypeDeclarationNode) Position() int
- func (n *TypeDeclarationNode) SetComment(c *CommentNode)
- func (n *TypeDeclarationNode) String() string
- type UnaryNode
- type ValueType
Constants ¶
const ( KW_And = "AND" KW_Or = "OR" KW_True = "TRUE" KW_False = "FALSE" KW_Var = "var" KW_Lambda = "lambda" )
Variables ¶
var MissingValue = &Missing{}
Functions ¶
func FindFunctionCalls ¶ added in v1.3.0
FindFunctionCalls walks all nodes and returns a list of name of function calls.
func FindReferenceVariables ¶ added in v1.3.0
FindReferenceVariables walks all nodes and returns a list of name from reference variables.
func IsCompOperator ¶
True if token type is an operator used in comparisons.
func IsExprOperator ¶
True if token type is an operator used in mathematical or boolean expressions.
func IsLogicalOperator ¶
func IsMathOperator ¶
True if token type is an operator used in mathematical expressions.
Types ¶
type BinaryNode ¶
type BinaryNode struct { Left Node Right Node Operator TokenType Comment *CommentNode Parens bool MultiLine bool // contains filtered or unexported fields }
binaryNode holds two arguments and an operator.
func (*BinaryNode) Equal ¶
func (n *BinaryNode) Equal(o interface{}) bool
func (*BinaryNode) Format ¶
func (n *BinaryNode) Format(buf *bytes.Buffer, indent string, onNewLine bool)
func (*BinaryNode) SetComment ¶
func (n *BinaryNode) SetComment(c *CommentNode)
func (*BinaryNode) String ¶
func (n *BinaryNode) String() string
type BoolNode ¶
type BoolNode struct { Bool bool Comment *CommentNode // contains filtered or unexported fields }
boolNode holds one argument and an operator.
func (*BoolNode) SetComment ¶
func (n *BoolNode) SetComment(c *CommentNode)
type ChainNode ¶
type ChainNode struct { Left Node Right Node Operator TokenType Comment *CommentNode // contains filtered or unexported fields }
func (*ChainNode) SetComment ¶
func (n *ChainNode) SetComment(c *CommentNode)
type CommentNode ¶
type CommentNode struct { Comments []string // contains filtered or unexported fields }
Hold the contents of a comment
func (*CommentNode) CommentString ¶
func (n *CommentNode) CommentString() string
func (*CommentNode) Equal ¶
func (n *CommentNode) Equal(o interface{}) bool
func (*CommentNode) Format ¶
func (n *CommentNode) Format(buf *bytes.Buffer, indent string, onNewLine bool)
func (*CommentNode) String ¶
func (n *CommentNode) String() string
type DeclarationNode ¶
type DeclarationNode struct { Left *IdentifierNode Right Node Comment *CommentNode // contains filtered or unexported fields }
func (*DeclarationNode) Equal ¶
func (n *DeclarationNode) Equal(o interface{}) bool
func (*DeclarationNode) Format ¶
func (n *DeclarationNode) Format(buf *bytes.Buffer, indent string, onNewLine bool)
func (*DeclarationNode) SetComment ¶
func (n *DeclarationNode) SetComment(c *CommentNode)
func (*DeclarationNode) String ¶
func (n *DeclarationNode) String() string
type DurationNode ¶
type DurationNode struct { Dur time.Duration //the duration Literal string Comment *CommentNode // contains filtered or unexported fields }
durationNode holds a number: signed or unsigned integer or float. The value is parsed and stored under all the types that can represent the value. This simulates in a small amount of code the behavior of Go's ideal constants.
func (*DurationNode) Equal ¶
func (n *DurationNode) Equal(o interface{}) bool
func (*DurationNode) Format ¶
func (n *DurationNode) Format(buf *bytes.Buffer, indent string, onNewLine bool)
func (*DurationNode) SetComment ¶
func (n *DurationNode) SetComment(c *CommentNode)
func (*DurationNode) String ¶
func (n *DurationNode) String() string
type FunctionNode ¶
type FunctionNode struct { Type FuncType Func string // The identifier Args []Node Comment *CommentNode MultiLine bool // contains filtered or unexported fields }
Holds the a function call with its args
func (*FunctionNode) Equal ¶
func (n *FunctionNode) Equal(o interface{}) bool
func (*FunctionNode) Format ¶
func (n *FunctionNode) Format(buf *bytes.Buffer, indent string, onNewLine bool)
func (*FunctionNode) SetComment ¶
func (n *FunctionNode) SetComment(c *CommentNode)
func (*FunctionNode) String ¶
func (n *FunctionNode) String() string
type IdentifierNode ¶
type IdentifierNode struct { Ident string // The identifier Comment *CommentNode // contains filtered or unexported fields }
Holds the textual representation of an identifier
func (*IdentifierNode) Equal ¶
func (n *IdentifierNode) Equal(o interface{}) bool
func (*IdentifierNode) Format ¶
func (n *IdentifierNode) Format(buf *bytes.Buffer, indent string, onNewLine bool)
func (*IdentifierNode) SetComment ¶
func (n *IdentifierNode) SetComment(c *CommentNode)
func (*IdentifierNode) String ¶
func (n *IdentifierNode) String() string
type LambdaNode ¶
type LambdaNode struct { Expression Node Comment *CommentNode // contains filtered or unexported fields }
Represents the beginning of a lambda expression
func ParseLambda ¶
func ParseLambda(text string) (*LambdaNode, error)
Parse returns a LambdaNode, created by parsing a lambda expression.
func (*LambdaNode) Equal ¶
func (n *LambdaNode) Equal(o interface{}) bool
func (*LambdaNode) ExpressionString ¶
func (n *LambdaNode) ExpressionString() string
func (*LambdaNode) Format ¶
func (n *LambdaNode) Format(buf *bytes.Buffer, indent string, onNewLine bool)
func (*LambdaNode) SetComment ¶
func (n *LambdaNode) SetComment(c *CommentNode)
func (*LambdaNode) String ¶
func (n *LambdaNode) String() string
type ListNode ¶
type ListNode struct { Nodes []Node Comment *CommentNode // contains filtered or unexported fields }
Holds the list of other nodes
func (*ListNode) SetComment ¶
func (n *ListNode) SetComment(c *CommentNode)
type Node ¶
type Node interface { Position String() string Format(buf *bytes.Buffer, indent string, onNewLine bool) // Report whether to nodes are functionally equal, ignoring position and comments Equal(interface{}) bool }
func Parse ¶
Parse returns a Node, created by parsing the DSL described in the argument string. If an error is encountered, parsing stops and a nil Node is returned with the error.
func ValueToLiteralNode ¶
Convert raw value to literal node, for all supported basic types.
type NumberNode ¶
type NumberNode struct { IsInt bool // Number has an integral value. IsFloat bool // Number has a floating-point value. Int64 int64 // The integer value. Float64 float64 // The floating-point value. Base int // The base of an integer value. Comment *CommentNode // contains filtered or unexported fields }
numberNode holds a number: signed or unsigned integer or float. The value is parsed and stored under all the types that can represent the value. This simulates in a small amount of code the behavior of Go's ideal constants.
func (*NumberNode) Equal ¶
func (n *NumberNode) Equal(o interface{}) bool
func (*NumberNode) Format ¶
func (n *NumberNode) Format(buf *bytes.Buffer, indent string, onNewLine bool)
func (*NumberNode) SetComment ¶
func (n *NumberNode) SetComment(c *CommentNode)
func (*NumberNode) String ¶
func (n *NumberNode) String() string
type ProgramNode ¶
type ProgramNode struct { Nodes []Node // contains filtered or unexported fields }
Holds a function call with its args
func (*ProgramNode) Add ¶
func (n *ProgramNode) Add(node Node)
func (*ProgramNode) Equal ¶
func (n *ProgramNode) Equal(o interface{}) bool
func (*ProgramNode) Format ¶
func (n *ProgramNode) Format(buf *bytes.Buffer, indent string, onNewLine bool)
func (*ProgramNode) String ¶
func (n *ProgramNode) String() string
type ReferenceNode ¶
type ReferenceNode struct { Reference string // The field reference Comment *CommentNode // contains filtered or unexported fields }
Holds the textual representation of an identifier
func (*ReferenceNode) Equal ¶
func (n *ReferenceNode) Equal(o interface{}) bool
func (*ReferenceNode) Format ¶
func (n *ReferenceNode) Format(buf *bytes.Buffer, indent string, onNewLine bool)
func (*ReferenceNode) SetComment ¶
func (n *ReferenceNode) SetComment(c *CommentNode)
func (*ReferenceNode) String ¶
func (n *ReferenceNode) String() string
type RegexNode ¶
type RegexNode struct { Regex *regexp.Regexp Literal string Comment *CommentNode // contains filtered or unexported fields }
Holds the textual representation of a regex literal
func (*RegexNode) SetComment ¶
func (n *RegexNode) SetComment(c *CommentNode)
type StarNode ¶
type StarNode struct { Comment *CommentNode // contains filtered or unexported fields }
Represents a standalone '*' token.
func (*StarNode) SetComment ¶
func (n *StarNode) SetComment(c *CommentNode)
type StringNode ¶
type StringNode struct { Literal string // The string literal TripleQuotes bool Comment *CommentNode // contains filtered or unexported fields }
Holds the textual representation of a string literal
func (*StringNode) Equal ¶
func (n *StringNode) Equal(o interface{}) bool
func (*StringNode) Format ¶
func (n *StringNode) Format(buf *bytes.Buffer, indent string, onNewLine bool)
func (*StringNode) SetComment ¶
func (n *StringNode) SetComment(c *CommentNode)
func (*StringNode) String ¶
func (n *StringNode) String() string
type TokenType ¶
type TokenType int
const ( TokenError TokenType = iota TokenEOF TokenVar TokenAsgn TokenDot TokenPipe TokenAt TokenIdent TokenReference TokenLambda TokenNumber TokenString TokenDuration TokenLParen TokenRParen TokenLSBracket TokenRSBracket TokenComma TokenNot TokenTrue TokenFalse TokenRegex TokenComment TokenStar TokenPlus TokenMinus TokenMult TokenDiv TokenMod TokenAnd TokenOr TokenEqual TokenNotEqual TokenLess TokenGreater TokenLessEqual TokenGreaterEqual TokenRegexEqual TokenRegexNotEqual )
type TypeDeclarationNode ¶
type TypeDeclarationNode struct { Node *IdentifierNode Type *IdentifierNode Comment *CommentNode // contains filtered or unexported fields }
func (*TypeDeclarationNode) Equal ¶
func (n *TypeDeclarationNode) Equal(o interface{}) bool
func (*TypeDeclarationNode) Format ¶
func (n *TypeDeclarationNode) Format(buf *bytes.Buffer, indent string, onNewLine bool)
func (*TypeDeclarationNode) SetComment ¶
func (n *TypeDeclarationNode) SetComment(c *CommentNode)
func (*TypeDeclarationNode) String ¶
func (n *TypeDeclarationNode) String() string
type UnaryNode ¶
type UnaryNode struct { Node Node Operator TokenType Comment *CommentNode // contains filtered or unexported fields }
unaryNode holds one argument and an operator.
func (*UnaryNode) SetComment ¶
func (n *UnaryNode) SetComment(c *CommentNode)