postfix

package
v0.24.8 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2024 License: BSD-3-Clause Imports: 2 Imported by: 0

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

func (p *Pipe) AddPipe() (err error)

AddPipe delineates a link in a chain of functions.

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

func (s *Shunt) AddExpression(prev []Function)

AddExpression generated by another shunt or pipe.

func (*Shunt) AddFunction

func (s *Shunt) AddFunction(next Function)

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.

type Yards

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

Yards contains a stack of shunting yards: one for each pending sub/expression.

func (Yards) Len

func (ys Yards) Len() int

Len returns count of pending sub/expressions.

func (*Yards) NewYard

func (ys *Yards) NewYard()

NewYard starts a new sub/expression.

func (*Yards) Pop

func (ys *Yards) Pop() (ret Yard)

Pop ends a sub/expression.

func (Yards) Top

func (ys Yards) Top() (ret *Yard)

Top aka innermost sub/expression.

Jump to

Keyboard shortcuts

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