Documentation ¶
Overview ¶
Package postfix translates streams of infix functions into postfix expressions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Expression ¶
type Expression []Function
Expression provides a series of postfix functions: even primitive values are represented here as zero-arity functions returning the value in question.
func (Expression) String ¶
func (x Expression) String() string
type Function ¶
type Function interface { // Arity the number of required function arguments; // Should be a constant number for each function instance. Arity() int // Precedence for infix priority; only has meaning where Arity is non-zero. // Should be a constant number for each function instance. Precedence() int }
Function element of an Expression. Examples of function(s) are mathematical and boolean operators, if-else blocks, commands, etc. See package tapestry/template/types for specific functions.
type Pipe ¶
type Pipe struct { Shunt // contains filtered or unexported fields }
Pipe extends the shunting yard to combine chains of expressions. Each link in the chain becomes the last parameter of the next expression in the chain. For example: Greeting | Capitalize | Append: " World!" where greeting is "hello" would become "Hello World!"
func (*Pipe) GetExpression ¶
func (p *Pipe) GetExpression() (ret Expression, err error)
GetExpression returns the pipe's postfix ordered output, clearing the pipe.
type Shunt ¶
type Shunt struct {
// contains filtered or unexported fields
}
Shunt-ing yard ( dijkstra ) to convert an infix function stream to a postfix function list. The key differences to the traditional algorithm are:
- Tokens are replaced by Functions; operands are zero-arity functions ( which return the value of the operand. )
- Uses a separate yard for each sub-expression ( rather than making parentheses an element in the symbol stream. )
func (*Shunt) AddExpression ¶
AddExpression generated by another shunt or pipe.
func (*Shunt) AddFunction ¶
AddFunction ( the next (infix) operation ) to the pending postfix expression. Zero-arity functions are moved directly to the output, otherwise they are shunted to a yard such that higher precedence functions will pop out of the yard first, leaving
func (*Shunt) BeginSubExpression ¶
func (s *Shunt) BeginSubExpression()
BeginSubExpression delineates an opening parenthesis in a stream of functions.
func (*Shunt) EndSubExpression ¶
func (s *Shunt) EndSubExpression()
EndSubExpression indicates a closing parenthesis in a stream of functions.
func (*Shunt) GetExpression ¶
func (s *Shunt) GetExpression() (ret Expression, err error)
GetExpression returns the shunt's postfix ordered output, clearing the shunt.
type Yard ¶
type Yard struct {
// contains filtered or unexported fields
}
Yard containing functions suspended in their transition from infix to postfix.