core

package
v0.0.0-...-a6088cc Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2015 License: MIT Imports: 13 Imported by: 3

Documentation

Index

Constants

View Source
const (
	OR LogicalOperator = iota
	AND
	UnknownLogicalOperator

	Equals ComparisonOperator = iota
	NotEquals
	LessThan
	GreaterThan
	LessThanOrEqual
	GreaterThanOrEqual
	UnknownComparisonOperator

	String Type = iota
	Nil
	Int
	Int64
	Uint
	Float64
	Complex128
	Bool
	Time
	Today
	Array
	Unknown
)
View Source
const (
	NormalState ExecutionState = iota
	BreakState
	ContinueState

	OutputTag TagType = iota
	UnsafeTag
	CodeTag
	CommentTag
	NoTag
)

Variables

View Source
var (
	TrueCondition  = &BooleanCondition{&StaticValue{true}}
	FalseCondition = &BooleanCondition{&StaticValue{false}}
)
View Source
var Builtins = make(map[string]interface{})
View Source
var BytePool = bytepool.New(65536, 64)
View Source
var FunctionAliases = make(map[string]map[string]interface{})
View Source
var OneStaticValue = &StaticValue{1}
View Source
var OtherAliases = make(map[string]map[string]interface{})
View Source
var TypeOperations = map[Type]map[ComparisonOperator]ConditionResolver{
	String: map[ComparisonOperator]ConditionResolver{
		Equals:   func(left, right interface{}) bool { return left.(string) == right.(string) },
		LessThan: func(left, right interface{}) bool { return left.(string) < right.(string) },
	},
	Nil: map[ComparisonOperator]ConditionResolver{
		Equals:   func(left, right interface{}) bool { return left == nil && right == nil },
		LessThan: func(left, right interface{}) bool { return false },
	},
	Int: map[ComparisonOperator]ConditionResolver{
		Equals:   func(left, right interface{}) bool { return left.(int) == right.(int) },
		LessThan: func(left, right interface{}) bool { return left.(int) < right.(int) },
	},
	Int64: map[ComparisonOperator]ConditionResolver{
		Equals:   func(left, right interface{}) bool { return left.(int64) == right.(int64) },
		LessThan: func(left, right interface{}) bool { return left.(int64) < right.(int64) },
	},
	Uint: map[ComparisonOperator]ConditionResolver{
		Equals:   func(left, right interface{}) bool { return left.(uint) == right.(uint) },
		LessThan: func(left, right interface{}) bool { return left.(uint) < right.(uint) },
	},
	Float64: map[ComparisonOperator]ConditionResolver{
		Equals:   func(left, right interface{}) bool { return left.(float64) == right.(float64) },
		LessThan: func(left, right interface{}) bool { return left.(float64) < right.(float64) },
	},
	Complex128: map[ComparisonOperator]ConditionResolver{
		Equals:   func(left, right interface{}) bool { return left.(complex128) == right.(complex128) },
		LessThan: func(left, right interface{}) bool { return false },
	},
	Bool: map[ComparisonOperator]ConditionResolver{
		Equals:   func(left, right interface{}) bool { return left.(bool) == right.(bool) },
		LessThan: func(left, right interface{}) bool { return false },
	},
	Time: map[ComparisonOperator]ConditionResolver{
		Equals:   func(left, right interface{}) bool { return left.(time.Time).Unix() == right.(time.Time).Unix() },
		LessThan: func(left, right interface{}) bool { return left.(time.Time).Unix() < right.(time.Time).Unix() },
	},
	Today: map[ComparisonOperator]ConditionResolver{
		Equals: func(left, right interface{}) bool {
			l, r := left.(time.Time), right.(time.Time)
			return l.YearDay() == r.YearDay() && l.Year() == r.Year()
		},
		LessThan: func(left, right interface{}) bool {
			l, r := left.(time.Time), right.(time.Time)
			if l.Year() > r.Year() {
				return false
			}
			if l.Year() < r.Year() {
				return true
			}
			return l.YearDay() < r.YearDay()
		},
	},
	Array: map[ComparisonOperator]ConditionResolver{
		Equals:   func(left, right interface{}) bool { return reflect.DeepEqual(left, right) },
		LessThan: func(left, right interface{}) bool { return reflect.ValueOf(left).Len() < reflect.ValueOf(right).Len() },
	},
}

Functions

func EqualsComparison

func EqualsComparison(left, right interface{}) bool

func GreaterThanComparison

func GreaterThanComparison(left, right interface{}) bool

func GreaterThanOrEqualComparison

func GreaterThanOrEqualComparison(left, right interface{}) bool

func IntBuiltin

func IntBuiltin(value interface{}) interface{}

func LenBuiltin

func LenBuiltin(value interface{}) int

func LessThanComparison

func LessThanComparison(left, right interface{}) bool

func LessThanOrEqualComparison

func LessThanOrEqualComparison(left, right interface{}) bool

func NotEqualsComparison

func NotEqualsComparison(left, right interface{}) bool

func RegisterAlias

func RegisterAlias(packageName, memberName string, f interface{})

func RegisterAliases

func RegisterAliases(packageName string, data ...interface{})

func RegisterBuiltin

func RegisterBuiltin(name string, f interface{})

func YieldBuiltin

func YieldBuiltin(name string, context *Context) interface{}

Types

type AdditiveValue

type AdditiveValue struct {
	// contains filtered or unexported fields
}

func (*AdditiveValue) Id

func (v *AdditiveValue) Id() string

func (*AdditiveValue) Resolve

func (v *AdditiveValue) Resolve(context *Context) interface{}

func (*AdditiveValue) ResolveAll

func (v *AdditiveValue) ResolveAll(context *Context) []interface{}

type Assignment

type Assignment struct {
	// contains filtered or unexported fields
}

func (*Assignment) AddCode

func (c *Assignment) AddCode(Code) error

func (*Assignment) AddExecutable

func (c *Assignment) AddExecutable(Executable)

func (*Assignment) Execute

func (c *Assignment) Execute(context *Context) ExecutionState

func (*Assignment) IsCodeContainer

func (c *Assignment) IsCodeContainer() bool

func (*Assignment) IsContentContainer

func (c *Assignment) IsContentContainer() bool

func (*Assignment) IsSibling

func (c *Assignment) IsSibling() bool

func (*Assignment) Rollback

func (c *Assignment) Rollback(context *Context)

type BooleanCondition

type BooleanCondition struct {
	// contains filtered or unexported fields
}

func (*BooleanCondition) IsTrue

func (c *BooleanCondition) IsTrue(context *Context) bool

type Code

type Code interface {
	Executable
	IsCodeContainer() bool
	IsContentContainer() bool
	IsSibling() bool
	AddExecutable(Executable)
	AddCode(Code) error
}

type Codes

type Codes struct {
	Trim bool
	List []Code
}

type Coercable

type Coercable interface {
	ResolveCoerce(context *Context, to reflect.Type) reflect.Value
}

type ComparisonOperator

type ComparisonOperator int

type Condition

type Condition struct {
	// contains filtered or unexported fields
}

represents a conditions (such as x == y)

func (*Condition) IsTrue

func (c *Condition) IsTrue(context *Context) bool

type ConditionGroup

type ConditionGroup struct {
	// contains filtered or unexported fields
}

represents a group of conditions

func (*ConditionGroup) IsTrue

func (g *ConditionGroup) IsTrue(context *Context) bool

type ConditionResolver

type ConditionResolver func(left, right interface{}) bool

Resolves a condition

type Context

type Context struct {
	Writer   io.Writer
	Data     map[string]interface{}
	Counters map[string]int
	Contents map[string]*bytepool.Bytes
}

type DefaultLogger

type DefaultLogger struct {
	// contains filtered or unexported fields
}

func (*DefaultLogger) Error

func (l *DefaultLogger) Error(v ...interface{})

type DefaultYieldValue

type DefaultYieldValue struct{}

func (*DefaultYieldValue) Id

func (v *DefaultYieldValue) Id() string

func (*DefaultYieldValue) Resolve

func (v *DefaultYieldValue) Resolve(context *Context) interface{}

func (*DefaultYieldValue) ResolveAll

func (v *DefaultYieldValue) ResolveAll(context *Context) []interface{}

type DynamicFieldType

type DynamicFieldType int
const (
	FieldType DynamicFieldType = iota
	MethodType
	IndexedType
)

type DynamicValue

type DynamicValue struct {
	// contains filtered or unexported fields
}

func (*DynamicValue) Id

func (v *DynamicValue) Id() string

func (*DynamicValue) Resolve

func (v *DynamicValue) Resolve(context *Context) interface{}

func (*DynamicValue) ResolveAll

func (v *DynamicValue) ResolveAll(context *Context) []interface{}

func (*DynamicValue) ResolveCorece

func (v *DynamicValue) ResolveCorece(context *Context, to reflect.Type) interface{}

type Executable

type Executable interface {
	Execute(context *Context) ExecutionState
}

type ExecutionState

type ExecutionState int

type Literal

type Literal struct {
	// contains filtered or unexported fields
}

func (*Literal) Execute

func (l *Literal) Execute(context *Context) ExecutionState

type Logger

type Logger interface {
	Error(v ...interface{})
}
var Log Logger = &DefaultLogger{log.New(os.Stdout, "[gerb] ", log.Ldate|log.Ltime)}

type LogicalOperator

type LogicalOperator int

type ModulatedValue

type ModulatedValue struct {
	// contains filtered or unexported fields
}

func (*ModulatedValue) Id

func (v *ModulatedValue) Id() string

func (*ModulatedValue) Resolve

func (v *ModulatedValue) Resolve(context *Context) interface{}

func (*ModulatedValue) ResolveAll

func (v *ModulatedValue) ResolveAll(context *Context) []interface{}

type MultiplicativeValue

type MultiplicativeValue struct {
	// contains filtered or unexported fields
}

func (*MultiplicativeValue) Id

func (v *MultiplicativeValue) Id() string

func (*MultiplicativeValue) Resolve

func (v *MultiplicativeValue) Resolve(context *Context) interface{}

func (*MultiplicativeValue) ResolveAll

func (v *MultiplicativeValue) ResolveAll(context *Context) []interface{}

type NormalContainer

type NormalContainer struct {
	// contains filtered or unexported fields
}

func (*NormalContainer) AddExecutable

func (c *NormalContainer) AddExecutable(executable Executable)

func (*NormalContainer) Execute

func (c *NormalContainer) Execute(context *Context) ExecutionState

type OperationFactory

type OperationFactory func(a, b Value) Value

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

func NewParser

func NewParser(data []byte) *Parser

func (*Parser) Backwards

func (p *Parser) Backwards(length int)

func (*Parser) Consume

func (p *Parser) Consume() byte

func (*Parser) ConsumeIf

func (p *Parser) ConsumeIf(bytes []byte) bool

func (*Parser) Dump

func (p *Parser) Dump(prefix string)

func (*Parser) Error

func (p *Parser) Error(s string) error

func (*Parser) Next

func (p *Parser) Next() byte

func (*Parser) Peek

func (p *Parser) Peek() byte

func (*Parser) Prev

func (p *Parser) Prev() byte

func (*Parser) ReadArgs

func (p *Parser) ReadArgs() ([]Value, error)

func (*Parser) ReadAssignment

func (p *Parser) ReadAssignment() (*Assignment, error)

func (*Parser) ReadBuiltin

func (p *Parser) ReadBuiltin(invert bool) (Value, bool)

func (*Parser) ReadChar

func (p *Parser) ReadChar(negate, invert bool) (Value, error)

func (*Parser) ReadCloseTag

func (p *Parser) ReadCloseTag() error

func (*Parser) ReadComment

func (p *Parser) ReadComment() (trim bool, err error)

func (*Parser) ReadComparisonOperator

func (p *Parser) ReadComparisonOperator() ComparisonOperator

func (*Parser) ReadConditionGroup

func (p *Parser) ReadConditionGroup(parentheses bool) (Verifiable, error)

func (*Parser) ReadDynamic

func (p *Parser) ReadDynamic(negate, invert bool) (Value, error)

func (*Parser) ReadIndexing

func (p *Parser) ReadIndexing() ([]Value, error)

func (*Parser) ReadLiteral

func (p *Parser) ReadLiteral(trim bool) *Literal

func (*Parser) ReadLogicalOperator

func (p *Parser) ReadLogicalOperator() LogicalOperator

func (*Parser) ReadNumber

func (p *Parser) ReadNumber(negate, invert bool) (Value, error)

func (*Parser) ReadString

func (p *Parser) ReadString(negate, invert bool, end byte, allowEscape bool) (Value, error)

func (*Parser) ReadTagType

func (p *Parser) ReadTagType() TagType

func (*Parser) ReadToken

func (p *Parser) ReadToken() (string, error)

func (*Parser) ReadTokenList

func (p *Parser) ReadTokenList() ([]string, error)

func (*Parser) ReadValue

func (p *Parser) ReadValue() (Value, error)

func (*Parser) ReadValueList

func (p *Parser) ReadValueList() ([]Value, error)

func (*Parser) SkipSpaces

func (p *Parser) SkipSpaces() byte

func (*Parser) SkipUntil

func (p *Parser) SkipUntil(b byte) bool

func (*Parser) TagContains

func (p *Parser) TagContains(b byte) bool

type PlusEqualValue

type PlusEqualValue struct {
	// contains filtered or unexported fields
}

func (*PlusEqualValue) Id

func (v *PlusEqualValue) Id() string

func (*PlusEqualValue) Resolve

func (v *PlusEqualValue) Resolve(context *Context) interface{}

func (*PlusEqualValue) ResolveAll

func (v *PlusEqualValue) ResolveAll(context *Context) []interface{}

type SilentLogger

type SilentLogger struct{}

func (*SilentLogger) Error

func (l *SilentLogger) Error(v ...interface{})

type StaticValue

type StaticValue struct {
	// contains filtered or unexported fields
}

func (*StaticValue) Id

func (v *StaticValue) Id() string

func (*StaticValue) Resolve

func (v *StaticValue) Resolve(context *Context) interface{}

func (*StaticValue) ResolveAll

func (v *StaticValue) ResolveAll(context *Context) []interface{}

func (*StaticValue) ResolveCoerce

func (v *StaticValue) ResolveCoerce(context *Context, to reflect.Type) reflect.Value

type TagType

type TagType int

type Type

type Type int

type UnaryOperationFactory

type UnaryOperationFactory func(a Value) Value

type Value

type Value interface {
	Resolve(context *Context) interface{}
	ResolveAll(context *Context) []interface{}
	Id() string
}

func AddOperation

func AddOperation(a, b Value) Value

func DecrementOperation

func DecrementOperation(a Value) Value

func DivideOperation

func DivideOperation(a, b Value) Value

func IncrementOperation

func IncrementOperation(a Value) Value

func MinusEqualOperation

func MinusEqualOperation(a, b Value) Value

func ModuloOperation

func ModuloOperation(a, b Value) Value

func MultiplyOperation

func MultiplyOperation(a, b Value) Value

func PlusEqualOperation

func PlusEqualOperation(a, b Value) Value

func SubOperation

func SubOperation(a, b Value) Value

type Verifiable

type Verifiable interface {
	IsTrue(context *Context) bool
}

Jump to

Keyboard shortcuts

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