ast

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2017 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KW_And    = "AND"
	KW_Or     = "OR"
	KW_True   = "TRUE"
	KW_False  = "FALSE"
	KW_Var    = "var"
	KW_Lambda = "lambda"
)

Variables

This section is empty.

Functions

func IsCompOperator

func IsCompOperator(typ TokenType) bool

True if token type is an operator used in comparisons.

func IsExprOperator

func IsExprOperator(typ TokenType) bool

True if token type is an operator used in mathematical or boolean expressions.

func IsLogicalOperator

func IsLogicalOperator(typ TokenType) bool

func IsMathOperator

func IsMathOperator(typ TokenType) bool

True if token type is an operator used in mathematical expressions.

func ZeroValue

func ZeroValue(t ValueType) interface{}

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) Char

func (p BinaryNode) Char() int

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) Line

func (p BinaryNode) Line() int

func (BinaryNode) Position

func (p BinaryNode) Position() int

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) Char

func (p BoolNode) Char() int

func (*BoolNode) Equal

func (n *BoolNode) Equal(o interface{}) bool

func (*BoolNode) Format

func (n *BoolNode) Format(buf *bytes.Buffer, indent string, onNewLine bool)

func (BoolNode) Line

func (p BoolNode) Line() int

func (BoolNode) Position

func (p BoolNode) Position() int

func (*BoolNode) SetComment

func (n *BoolNode) SetComment(c *CommentNode)

func (*BoolNode) String

func (n *BoolNode) String() string

type ChainNode

type ChainNode struct {
	Left     Node
	Right    Node
	Operator TokenType
	Comment  *CommentNode
	// contains filtered or unexported fields
}

func (ChainNode) Char

func (p ChainNode) Char() int

func (*ChainNode) Equal

func (n *ChainNode) Equal(o interface{}) bool

func (*ChainNode) Format

func (n *ChainNode) Format(buf *bytes.Buffer, indent string, onNewLine bool)

func (ChainNode) Line

func (p ChainNode) Line() int

func (ChainNode) Position

func (p ChainNode) Position() int

func (*ChainNode) SetComment

func (n *ChainNode) SetComment(c *CommentNode)

func (*ChainNode) String

func (n *ChainNode) String() string

type CommentNode

type CommentNode struct {
	Comments []string
	// contains filtered or unexported fields
}

Hold the contents of a comment

func (CommentNode) Char

func (p CommentNode) Char() int

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) Line

func (p CommentNode) Line() int

func (CommentNode) Position

func (p CommentNode) Position() int

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) Char

func (p DeclarationNode) Char() int

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) Line

func (p DeclarationNode) Line() int

func (DeclarationNode) Position

func (p DeclarationNode) Position() int

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) Char

func (p DurationNode) Char() int

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) Line

func (p DurationNode) Line() int

func (DurationNode) Position

func (p DurationNode) Position() int

func (*DurationNode) SetComment

func (n *DurationNode) SetComment(c *CommentNode)

func (*DurationNode) String

func (n *DurationNode) String() string

type FuncType

type FuncType int
const (
	GlobalFunc FuncType = iota
	ChainFunc
	PropertyFunc
	DynamicFunc
)

func (FuncType) String

func (ft FuncType) 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) Char

func (p FunctionNode) Char() int

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) Line

func (p FunctionNode) Line() int

func (FunctionNode) Position

func (p FunctionNode) Position() int

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) Char

func (p IdentifierNode) Char() int

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) Line

func (p IdentifierNode) Line() int

func (IdentifierNode) Position

func (p IdentifierNode) Position() int

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) Char

func (p LambdaNode) Char() int

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) Line

func (p LambdaNode) Line() int

func (LambdaNode) Position

func (p LambdaNode) Position() int

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) Char

func (p ListNode) Char() int

func (*ListNode) Equal

func (n *ListNode) Equal(o interface{}) bool

func (*ListNode) Format

func (n *ListNode) Format(buf *bytes.Buffer, indent string, onNewLine bool)

func (ListNode) Line

func (p ListNode) Line() int

func (ListNode) Position

func (p ListNode) Position() int

func (*ListNode) SetComment

func (n *ListNode) SetComment(c *CommentNode)

func (*ListNode) String

func (n *ListNode) String() string

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

func Parse(text string) (Node, error)

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

func ValueToLiteralNode(pos Position, v interface{}) (Node, error)

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) Char

func (p NumberNode) Char() int

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) Line

func (p NumberNode) Line() int

func (NumberNode) Position

func (p NumberNode) Position() int

func (*NumberNode) SetComment

func (n *NumberNode) SetComment(c *CommentNode)

func (*NumberNode) String

func (n *NumberNode) String() string

type Position

type Position interface {
	Position() int // byte position of start of node in full original input string
	Line() int
	Char() int
}

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) Char

func (p ProgramNode) Char() int

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) Line

func (p ProgramNode) Line() int

func (ProgramNode) Position

func (p ProgramNode) Position() int

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) Char

func (p ReferenceNode) Char() int

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) Line

func (p ReferenceNode) Line() int

func (ReferenceNode) Position

func (p ReferenceNode) Position() int

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) Char

func (p RegexNode) Char() int

func (*RegexNode) Equal

func (n *RegexNode) Equal(o interface{}) bool

func (*RegexNode) Format

func (n *RegexNode) Format(buf *bytes.Buffer, indent string, onNewLine bool)

func (RegexNode) Line

func (p RegexNode) Line() int

func (RegexNode) Position

func (p RegexNode) Position() int

func (*RegexNode) SetComment

func (n *RegexNode) SetComment(c *CommentNode)

func (*RegexNode) String

func (n *RegexNode) String() string

type StarNode

type StarNode struct {
	Comment *CommentNode
	// contains filtered or unexported fields
}

Represents a standalone '*' token.

func (StarNode) Char

func (p StarNode) Char() int

func (*StarNode) Equal

func (n *StarNode) Equal(o interface{}) bool

func (*StarNode) Format

func (n *StarNode) Format(buf *bytes.Buffer, indent string, onNewLine bool)

func (StarNode) Line

func (p StarNode) Line() int

func (StarNode) Position

func (p StarNode) Position() int

func (*StarNode) SetComment

func (n *StarNode) SetComment(c *CommentNode)

func (*StarNode) String

func (n *StarNode) String() string

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) Char

func (p StringNode) Char() int

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) Line

func (p StringNode) Line() int

func (StringNode) Position

func (p StringNode) Position() int

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
)

func (TokenType) String

func (t TokenType) String() string

String representation of an TokenType

type TypeDeclarationNode

type TypeDeclarationNode struct {
	Node    *IdentifierNode
	Type    *IdentifierNode
	Comment *CommentNode
	// contains filtered or unexported fields
}

func (TypeDeclarationNode) Char

func (p TypeDeclarationNode) Char() int

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) Line

func (p TypeDeclarationNode) Line() int

func (TypeDeclarationNode) Position

func (p TypeDeclarationNode) Position() int

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) Char

func (p UnaryNode) Char() int

func (*UnaryNode) Equal

func (n *UnaryNode) Equal(o interface{}) bool

func (*UnaryNode) Format

func (n *UnaryNode) Format(buf *bytes.Buffer, indent string, onNewLine bool)

func (UnaryNode) Line

func (p UnaryNode) Line() int

func (UnaryNode) Position

func (p UnaryNode) Position() int

func (*UnaryNode) SetComment

func (n *UnaryNode) SetComment(c *CommentNode)

func (*UnaryNode) String

func (n *UnaryNode) String() string

type ValueType

type ValueType uint8
const (
	InvalidType ValueType = iota << 1
	TFloat
	TInt
	TString
	TBool
	TRegex
	TTime
	TDuration
	TLambda
	TList
	TStar
)

func TypeOf

func TypeOf(v interface{}) ValueType

func (ValueType) String

func (v ValueType) String() string

Jump to

Keyboard shortcuts

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