Documentation
¶
Overview ¶
Package poslang provides an implementation of the POS expression.
POS is a small language to write a specification of Pos()/End() methods of ast.Node types. The syntax of POS is described in ast package documentation. See https://pkg.go.dev/github.com/cloudspannerecosystem/memefish/ast.
This package provides:
- types for the POS expression
- a parser for the POS expression
- an interpreter of the POS expression
Index ¶
- type BoolExpr
- type Expr
- type IfThenElse
- type IntExpr
- type IntLiteral
- type Len
- type NodeChoice
- type NodeEnd
- type NodeExpr
- type NodePos
- type NodeSliceExpr
- type NodeSliceIndex
- type NodeSliceLast
- type PosAdd
- type PosChoice
- type PosExpr
- type StringExpr
- type Var
- func (v *Var) BoolExprToGo(x string) string
- func (v *Var) EvalBool(x any) bool
- func (v *Var) EvalNode(x any) node
- func (v *Var) EvalNodeSlice(x any) []node
- func (v *Var) EvalPos(x any) token.Pos
- func (v *Var) EvalString(x any) string
- func (v *Var) NodeExprToGo(x string) string
- func (v *Var) NodeSliceExprToGo(x string) string
- func (v *Var) PosExprToGo(x string) string
- func (v *Var) StringExprToGo(x string) string
- func (v *Var) Unparse() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Expr ¶
type Expr interface {
// Unparse returns the string representation of this expression.
Unparse() string
}
Expr is an interface that represents a POS expression.
This means an untyped expression and a base interface of all typed expressions.
type IfThenElse ¶
IfThenElse represents a "(BoolExpr ? IntExpr1 : IntExpr2)" expression.
func (*IfThenElse) EvalInt ¶
func (i *IfThenElse) EvalInt(x any) int
func (*IfThenElse) IntExprToGo ¶
func (i *IfThenElse) IntExprToGo(x string) string
func (*IfThenElse) Unparse ¶
func (i *IfThenElse) Unparse() string
type IntLiteral ¶
type IntLiteral struct {
Value int
}
IntLiteral represents an integer literal in a POS expression.
func (*IntLiteral) EvalInt ¶
func (i *IntLiteral) EvalInt(x any) int
func (*IntLiteral) IntExprToGo ¶
func (i *IntLiteral) IntExprToGo(x string) string
func (*IntLiteral) Unparse ¶
func (i *IntLiteral) Unparse() string
type Len ¶
type Len struct {
Expr StringExpr
}
Len represents a "len(StringExpr)" expression.
func (*Len) IntExprToGo ¶
type NodeChoice ¶
type NodeChoice struct {
Exprs []NodeExpr
}
NodeChoice represents a "(NodeExpr1 ?? NodeExpr2 ?? ...)" expression.
func (*NodeChoice) EvalNode ¶
func (c *NodeChoice) EvalNode(x any) node
func (*NodeChoice) NodeExprToGo ¶
func (c *NodeChoice) NodeExprToGo(x string) string
func (*NodeChoice) Unparse ¶
func (c *NodeChoice) Unparse() string
type NodeEnd ¶
type NodeEnd struct {
Expr NodeExpr
}
NodeEnd represents a "NodeExpr.end" expression.
func (*NodeEnd) PosExprToGo ¶
type NodePos ¶
type NodePos struct {
Expr NodeExpr
}
NodePos represents a "NodeExpr.pos" expression.
func (*NodePos) PosExprToGo ¶
type NodeSliceExpr ¶
type NodeSliceExpr interface {
Expr
EvalNodeSlice(x any) []node
NodeSliceExprToGo(x string) string
}
NodeSliceExpr is a POS expression typed with []ast.Node.
type NodeSliceIndex ¶
type NodeSliceIndex struct {
Expr NodeSliceExpr
Index IntExpr
}
NodeSliceIndex represents a "NodeSliceExpr[IntExpr]" expression.
func (*NodeSliceIndex) EvalNode ¶
func (i *NodeSliceIndex) EvalNode(x any) node
func (*NodeSliceIndex) NodeExprToGo ¶
func (i *NodeSliceIndex) NodeExprToGo(x string) string
func (*NodeSliceIndex) Unparse ¶
func (i *NodeSliceIndex) Unparse() string
type NodeSliceLast ¶
type NodeSliceLast struct {
Expr NodeSliceExpr
}
NodeSliceLast represents a "NodeSliceExpr[$]" expression.
func (*NodeSliceLast) EvalNode ¶
func (l *NodeSliceLast) EvalNode(x any) node
func (*NodeSliceLast) NodeExprToGo ¶
func (l *NodeSliceLast) NodeExprToGo(x string) string
func (*NodeSliceLast) Unparse ¶
func (l *NodeSliceLast) Unparse() string
type PosChoice ¶
type PosChoice struct {
Exprs []PosExpr
}
PosChoice represents a "PosExpr1 || PosExpr2 || ..." expression.
func (*PosChoice) PosExprToGo ¶
type StringExpr ¶
StringExpr is a POS expression typed with string.
type Var ¶
type Var struct {
Name string
}
Var represents an untyped variable in a POS expression.
This type is determined by a context, i.e., on parsing.