poslang

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2025 License: MIT Imports: 7 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoolExpr

type BoolExpr interface {
	Expr
	EvalBool(x any) bool
	BoolExprToGo(x string) string
}

BoolExpr is a POS expression typed with bool.

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

type IfThenElse struct {
	Cond       BoolExpr
	Then, Else IntExpr
}

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 IntExpr

type IntExpr interface {
	Expr
	EvalInt(x any) int
	IntExprToGo(x string) string
}

IntExpr is a POS expression typed with int.

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

func (l *Len) EvalInt(x any) int

func (*Len) IntExprToGo

func (l *Len) IntExprToGo(x string) string

func (*Len) Unparse

func (l *Len) Unparse() string

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

func (e *NodeEnd) EvalPos(x any) token.Pos

func (*NodeEnd) PosExprToGo

func (e *NodeEnd) PosExprToGo(x string) string

func (*NodeEnd) Unparse

func (e *NodeEnd) Unparse() string

type NodeExpr

type NodeExpr interface {
	Expr
	EvalNode(x any) node
	NodeExprToGo(x string) string
}

NodeExpr is a POS expression typed with ast.Node.

type NodePos

type NodePos struct {
	Expr NodeExpr
}

NodePos represents a "NodeExpr.pos" expression.

func (*NodePos) EvalPos

func (p *NodePos) EvalPos(x any) token.Pos

func (*NodePos) PosExprToGo

func (p *NodePos) PosExprToGo(x string) string

func (*NodePos) Unparse

func (p *NodePos) Unparse() string

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 PosAdd

type PosAdd struct {
	Expr  PosExpr
	Value IntExpr
}

PosAdd represents a "PosExpr + IntExpr" expression.

func (*PosAdd) EvalPos

func (a *PosAdd) EvalPos(x any) token.Pos

func (*PosAdd) PosExprToGo

func (a *PosAdd) PosExprToGo(x string) string

func (*PosAdd) Unparse

func (a *PosAdd) Unparse() string

type PosChoice

type PosChoice struct {
	Exprs []PosExpr
}

PosChoice represents a "PosExpr1 || PosExpr2 || ..." expression.

func (*PosChoice) EvalPos

func (c *PosChoice) EvalPos(x any) token.Pos

func (*PosChoice) PosExprToGo

func (c *PosChoice) PosExprToGo(x string) string

func (*PosChoice) Unparse

func (c *PosChoice) Unparse() string

type PosExpr

type PosExpr interface {
	Expr
	EvalPos(x any) token.Pos
	PosExprToGo(x string) string
}

PosExpr is a POS expression typed with token.Pos.

func Parse

func Parse(source string) (expr PosExpr, err error)

Parse parses source as a POS expression.

type StringExpr

type StringExpr interface {
	Expr
	EvalString(x any) string
	StringExprToGo(x string) string
}

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.

func (*Var) BoolExprToGo

func (v *Var) BoolExprToGo(x string) string

func (*Var) EvalBool

func (v *Var) EvalBool(x any) bool

func (*Var) EvalNode

func (v *Var) EvalNode(x any) node

func (*Var) EvalNodeSlice

func (v *Var) EvalNodeSlice(x any) []node

func (*Var) EvalPos

func (v *Var) EvalPos(x any) token.Pos

func (*Var) EvalString

func (v *Var) EvalString(x any) string

func (*Var) NodeExprToGo

func (v *Var) NodeExprToGo(x string) string

func (*Var) NodeSliceExprToGo

func (v *Var) NodeSliceExprToGo(x string) string

func (*Var) PosExprToGo

func (v *Var) PosExprToGo(x string) string

func (*Var) StringExprToGo

func (v *Var) StringExprToGo(x string) string

func (*Var) Unparse

func (v *Var) Unparse() string

Jump to

Keyboard shortcuts

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