ast

package
v0.0.0-...-04f0d06 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddIndent

func AddIndent(ctx context.Context) context.Context

func Emit

func Emit(stmt Stmt, w io.Writer, options ...EmitOption) error

Emit takes a statement (or a list of statements) and emits them into the writer.

By default it emits the statements as a regular OpenSCAD file, but you can ask it to create an "amalgamated" file by passing the WithAmalgamate option.

func EmitFile

func EmitFile(filename string, w io.Writer, options ...EmitFileOption) error

func EmitString

func EmitString(stmt Stmt, options ...EmitOption) (string, error)

func GetIndent

func GetIndent(ctx context.Context) string

func Register

func Register(name string, s Stmt) error

func WriteFile

func WriteFile(filename string, options ...WriteFileOption) error

Types

type BareBlock

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

func NewBareBlock

func NewBareBlock(children ...Stmt) *BareBlock

func (*BareBlock) Add

func (b *BareBlock) Add(children ...Stmt) *BareBlock

func (*BareBlock) EmitStmt

func (b *BareBlock) EmitStmt(ctx *EmitContext, w io.Writer) error

type BinaryOp

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

func NewBinaryOp

func NewBinaryOp(op string, left, right interface{}) *BinaryOp

func (*BinaryOp) BindPrecedence

func (op *BinaryOp) BindPrecedence() int

func (*BinaryOp) EmitExpr

func (op *BinaryOp) EmitExpr(ctx *EmitContext, w io.Writer) error

func (*BinaryOp) EmitStmt

func (op *BinaryOp) EmitStmt(ctx *EmitContext, w io.Writer) error

func (*BinaryOp) Left

func (op *BinaryOp) Left() interface{}

func (*BinaryOp) Op

func (op *BinaryOp) Op() string

func (*BinaryOp) Rearrange

func (op *BinaryOp) Rearrange(op2 *BinaryOp) *BinaryOp

func (*BinaryOp) Right

func (op *BinaryOp) Right() interface{}

func (*BinaryOp) String

func (op *BinaryOp) String() string

type Call

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

func NewCall

func NewCall(name string) *Call

func (*Call) Add

func (c *Call) Add(children ...Stmt) *Call

func (*Call) EmitExpr

func (c *Call) EmitExpr(ctx *EmitContext, w io.Writer) error

func (*Call) EmitStmt

func (c *Call) EmitStmt(ctx *EmitContext, w io.Writer) error

func (*Call) Parameters

func (c *Call) Parameters(params ...interface{}) *Call

func (*Call) String

func (c *Call) String() string

type Children

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

Creates a call to the children() module.

func NewChildren

func NewChildren() *Children

func (*Children) EmitStmt

func (c *Children) EmitStmt(ctx *EmitContext, w io.Writer) error

func (*Children) Index

func (c *Children) Index(idx int) *Children

type Circle

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

func NewCircle

func NewCircle(radius interface{}) *Circle

func (*Circle) EmitExpr

func (c *Circle) EmitExpr(ctx *EmitContext, w io.Writer) error

func (*Circle) EmitStmt

func (c *Circle) EmitStmt(ctx *EmitContext, w io.Writer) error

func (*Circle) Fa

func (c *Circle) Fa(v int) *Circle

func (*Circle) Fn

func (c *Circle) Fn(v int) *Circle

func (*Circle) Fs

func (c *Circle) Fs(v int) *Circle

type Cube

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

func NewCube

func NewCube(width, depth, height interface{}) *Cube

func (*Cube) Center

func (c *Cube) Center(v bool) *Cube

func (*Cube) EmitStmt

func (c *Cube) EmitStmt(ctx *EmitContext, w io.Writer) error

func (*Cube) Fn

func (c *Cube) Fn(v int) *Cube

type Cylinder

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

func NewCylinder

func NewCylinder(height, radius1, radius2 interface{}) *Cylinder

To omit radius2, pass nil

func (*Cylinder) Center

func (c *Cylinder) Center(v bool) *Cylinder

func (*Cylinder) EmitStmt

func (c *Cylinder) EmitStmt(ctx *EmitContext, w io.Writer) error

func (*Cylinder) Fa

func (c *Cylinder) Fa(v int) *Cylinder

func (*Cylinder) Fn

func (c *Cylinder) Fn(v int) *Cylinder

func (*Cylinder) Fs

func (c *Cylinder) Fs(v int) *Cylinder

type Declare

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

func NewDeclare

func NewDeclare(v *Variable) *Declare

func (*Declare) EmitExpr

func (d *Declare) EmitExpr(ctx *EmitContext, w io.Writer) error

func (*Declare) EmitStmt

func (d *Declare) EmitStmt(ctx *EmitContext, w io.Writer) error

type Difference

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

func NewDifference

func NewDifference(children ...Stmt) *Difference

func (*Difference) Add

func (u *Difference) Add(s Stmt) *Difference

func (*Difference) Body

func (u *Difference) Body(s ...Stmt) *Difference

func (*Difference) EmitStmt

func (op *Difference) EmitStmt(ctx *EmitContext, w io.Writer) error

type ElseIfStmt

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

func (*ElseIfStmt) EmitStmt

func (eb *ElseIfStmt) EmitStmt(ctx *EmitContext, w io.Writer) error

type EmitContext

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

EmitContext holds the context for emitting OpenSCAD code. The object is immutable once created. To change the values, create a new context using one of the provided methods

func (*EmitContext) AllowAssignment

func (e *EmitContext) AllowAssignment() bool

func (*EmitContext) Amalgamate

func (e *EmitContext) Amalgamate() bool

func (*EmitContext) AsExpr

func (e *EmitContext) AsExpr() bool

func (*EmitContext) AsStmt

func (e *EmitContext) AsStmt() bool

func (*EmitContext) Copy

func (e *EmitContext) Copy() *EmitContext

func (*EmitContext) DecrIndent

func (e *EmitContext) DecrIndent() *EmitContext

func (*EmitContext) ForceExpr

func (e *EmitContext) ForceExpr() *EmitContext

func (*EmitContext) ForceStmt

func (e *EmitContext) ForceStmt() *EmitContext

func (*EmitContext) IncrIndent

func (e *EmitContext) IncrIndent() *EmitContext

func (*EmitContext) Indent

func (e *EmitContext) Indent() string

func (*EmitContext) WithAllowAssignment

func (e *EmitContext) WithAllowAssignment(allowAssignment bool) *EmitContext

func (*EmitContext) WithIndent

func (e *EmitContext) WithIndent(indent string) *EmitContext

type EmitFileOption

type EmitFileOption interface {
	EmitOption
	// contains filtered or unexported methods
}

type EmitFileWriteFileOption

type EmitFileWriteFileOption interface {
	EmitOption
	EmitFileOption
	EmitWriteFileOption
}

EmitFileWriteFileOption is an option that can be passed to Emit(), File() and WriteFile()

func WithAmalgamation

func WithAmalgamation() EmitFileWriteFileOption

func WithRegistry

func WithRegistry(r *Registry) EmitFileWriteFileOption

WithRegistry sets the registry to use when emitting the OpenSCAD code

type EmitOption

type EmitOption interface {
	option.Interface
	// contains filtered or unexported methods
}

type EmitWriteFileOption

type EmitWriteFileOption interface {
	EmitOption
	WriteFileOption
}

EmitWriteFileOption is an option that can be passed to Emit() and WriteFile()

type Expr

type Expr interface {
	EmitExpr(*EmitContext, io.Writer) error
}

Expr represents an expression in the OpenSCAD language.

An arbitrary object may be either an Expr or a Stmt, or both. For example, a *Variable is both an Expr and a Stmt.

type ForBlock

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

ForBlock represents a for loop block.

In OpenSCAD for can take two distinctive styles: one as an expression, and one as a statement. ForBlock the expression, use ForExpr

func NewFor

func NewFor(loopVars []*LoopVar) *ForBlock

func (*ForBlock) Add

func (f *ForBlock) Add(stmts ...Stmt) *ForBlock

func (*ForBlock) Body

func (f *ForBlock) Body(stmts ...Stmt) *ForBlock

func (*ForBlock) EmitStmt

func (f *ForBlock) EmitStmt(ctx *EmitContext, w io.Writer) error

type ForExpr

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

func NewForExpr

func NewForExpr(loopVars []*LoopVar) *ForExpr

func (*ForExpr) Body

func (f *ForExpr) Body(expr interface{}) *ForExpr

func (*ForExpr) EmitExpr

func (f *ForExpr) EmitExpr(ctx *EmitContext, w io.Writer) error

type ForRange

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

func NewForRange

func NewForRange(start, end interface{}) *ForRange

func (*ForRange) EmitExpr

func (fr *ForRange) EmitExpr(ctx *EmitContext, w io.Writer) error

func (*ForRange) Increment

func (fr *ForRange) Increment(incr interface{}) *ForRange

type Function

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

func NewFunction

func NewFunction(name string) *Function

func (*Function) Body

func (f *Function) Body(body interface{}) *Function

func (*Function) EmitExpr

func (f *Function) EmitExpr(ctx *EmitContext, w io.Writer) error

func (*Function) EmitStmt

func (f *Function) EmitStmt(ctx *EmitContext, w io.Writer) error

func (*Function) Name

func (f *Function) Name() string

func (*Function) Parameters

func (f *Function) Parameters(params ...*Variable) *Function

type Group

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

func NewGroup

func NewGroup(expr interface{}) *Group

func (*Group) EmitExpr

func (g *Group) EmitExpr(ctx *EmitContext, w io.Writer) error

func (*Group) String

func (g *Group) String() string

type Hull

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

func NewHull

func NewHull() *Hull

func (*Hull) Add

func (h *Hull) Add(s Stmt) *Hull

func (*Hull) Body

func (h *Hull) Body(s ...Stmt) *Hull

func (*Hull) EmitStmt

func (op *Hull) EmitStmt(ctx *EmitContext, w io.Writer) error

type IfExpr

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

func NewIfExpr

func NewIfExpr(cond interface{}) *IfExpr

func (*IfExpr) Body

func (ib *IfExpr) Body(body interface{}) *IfExpr

func (*IfExpr) EmitExpr

func (ib *IfExpr) EmitExpr(ctx *EmitContext, w io.Writer) error

type IfStmt

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

func NewIfStmt

func NewIfStmt(cond interface{}) *IfStmt

func (*IfStmt) AddElseIf

func (ib *IfStmt) AddElseIf(cond interface{}, stmts ...Stmt) *IfStmt

func (*IfStmt) Body

func (ib *IfStmt) Body(stmts ...Stmt) *IfStmt

func (*IfStmt) Else

func (ib *IfStmt) Else(stmts ...Stmt) *IfStmt

func (*IfStmt) EmitStmt

func (ib *IfStmt) EmitStmt(ctx *EmitContext, w io.Writer) error

type Include

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

func NewInclude

func NewInclude(name string) *Include

func (*Include) EmitStmt

func (i *Include) EmitStmt(ctx *EmitContext, w io.Writer) error

type Index

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

func NewIndex

func NewIndex(expr, index interface{}) *Index

func (*Index) EmitExpr

func (i *Index) EmitExpr(ctx *EmitContext, w io.Writer) error

func (*Index) String

func (i *Index) String() string

type Intersection

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

func NewIntersection

func NewIntersection(children ...Stmt) *Intersection

func (*Intersection) Add

func (u *Intersection) Add(s Stmt) *Intersection

func (*Intersection) Body

func (u *Intersection) Body(s ...Stmt) *Intersection

func (*Intersection) EmitStmt

func (op *Intersection) EmitStmt(ctx *EmitContext, w io.Writer) error

type LetBlock

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

func NewLetBlock

func NewLetBlock(variables ...*Variable) *LetBlock

func (*LetBlock) Add

func (l *LetBlock) Add(stmt ...Stmt) *LetBlock

func (*LetBlock) Body

func (l *LetBlock) Body(children ...Stmt) *LetBlock

func (*LetBlock) EmitStmt

func (l *LetBlock) EmitStmt(ctx *EmitContext, w io.Writer) error

type LetExpr

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

func NewLetExpr

func NewLetExpr(variables ...*Variable) *LetExpr

func (*LetExpr) EmitExpr

func (l *LetExpr) EmitExpr(ctx *EmitContext, w io.Writer) error

func (*LetExpr) Expr

func (l *LetExpr) Expr(expr interface{}) *LetExpr

type LinearExtrude

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

func NewLinearExtrude

func NewLinearExtrude(height, center, convexity, twist, scale interface{}, children ...Stmt) *LinearExtrude

func (*LinearExtrude) Add

func (l *LinearExtrude) Add(stmts ...Stmt) *LinearExtrude

func (*LinearExtrude) EmitStmt

func (l *LinearExtrude) EmitStmt(ctx *EmitContext, w io.Writer) error

func (*LinearExtrude) Fn

func (l *LinearExtrude) Fn(fn int) *LinearExtrude

type LookupStmt

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

func NewLookup

func NewLookup(key, values interface{}) *LookupStmt

func (*LookupStmt) EmitExpr

func (l *LookupStmt) EmitExpr(ctx *EmitContext, w io.Writer) error

type LoopVar

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

func NewLoopVar

func NewLoopVar(variable *Variable, expr interface{}) *LoopVar

func (*LoopVar) EmitExpr

func (lv *LoopVar) EmitExpr(ctx *EmitContext, w io.Writer) error

func (*LoopVar) String

func (lv *LoopVar) String() string

type Module

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

func NewModule

func NewModule(name string) *Module

func (*Module) Actions

func (m *Module) Actions(children ...Stmt) *Module

func (*Module) Add

func (m *Module) Add(child Stmt) *Module

func (*Module) Body

func (m *Module) Body(children ...Stmt) *Module

func (*Module) EmitStmt

func (m *Module) EmitStmt(ctx *EmitContext, w io.Writer) error

func (*Module) Parameters

func (m *Module) Parameters(params ...*Variable) *Module

type Point2D

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

func NewPoint2D

func NewPoint2D(x, y interface{}) *Point2D

func (*Point2D) EmitExpr

func (p *Point2D) EmitExpr(ctx *EmitContext, w io.Writer) error

type Point2DList

type Point2DList []*Point2D

func (*Point2DList) Add

func (l *Point2DList) Add(pt *Point2D)

func (Point2DList) EmitExpr

func (l Point2DList) EmitExpr(ctx *EmitContext, w io.Writer) error

type Polygon

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

func NewPolygon

func NewPolygon(points, paths interface{}) *Polygon

func (*Polygon) EmitStmt

func (p *Polygon) EmitStmt(ctx *EmitContext, w io.Writer) error

type Polyhedron

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

func NewPolyhedron

func NewPolyhedron(points, faces interface{}) *Polyhedron

func (*Polyhedron) Convexity

func (p *Polyhedron) Convexity(v interface{}) *Polyhedron

func (*Polyhedron) EmitStmt

func (p *Polyhedron) EmitStmt(ctx *EmitContext, w io.Writer) error

type Registry

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

Registry is used to register pieces of OpenSCAD code to a virtual filename.

func (*Registry) Lookup

func (r *Registry) Lookup(name string) (Stmt, bool)

func (*Registry) Register

func (r *Registry) Register(name string, s Stmt) error

type Rotate

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

func NewRotate

func NewRotate(v interface{}, children ...Stmt) *Rotate

func (*Rotate) Add

func (r *Rotate) Add(s Stmt) *Rotate

func (*Rotate) Body

func (r *Rotate) Body(children ...Stmt) *Rotate

func (*Rotate) EmitStmt

func (r *Rotate) EmitStmt(ctx *EmitContext, w io.Writer) error

type Sphere

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

func NewSphere

func NewSphere(radius interface{}) *Sphere

func (*Sphere) EmitStmt

func (s *Sphere) EmitStmt(ctx *EmitContext, w io.Writer) error

func (*Sphere) Fa

func (s *Sphere) Fa(v int) *Sphere

func (*Sphere) Fn

func (s *Sphere) Fn(v int) *Sphere

func (*Sphere) Fs

func (s *Sphere) Fs(v int) *Sphere

type Stmt

type Stmt interface {
	EmitStmt(*EmitContext, io.Writer) error
}

Stmt repreents an OpenSCAD statement.

An arbitrary object may be either an Expr or a Stmt, or both. For example, a *Variable is both an Expr and a Stmt.

func Lookup

func Lookup(name string) (Stmt, bool)

type Stmts

type Stmts []Stmt

Stmts is a sequence of statements.

func (*Stmts) Add

func (stmts *Stmts) Add(stmt Stmt)

func (Stmts) EmitStmt

func (stmts Stmts) EmitStmt(ctx *EmitContext, w io.Writer) error

type TernaryOp

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

func NewTernaryOp

func NewTernaryOp(condition, trueExpr, falseExpr interface{}) *TernaryOp

func (*TernaryOp) Condition

func (op *TernaryOp) Condition() interface{}

func (*TernaryOp) EmitExpr

func (op *TernaryOp) EmitExpr(ctx *EmitContext, w io.Writer) error

func (*TernaryOp) EmitStmt

func (op *TernaryOp) EmitStmt(ctx *EmitContext, w io.Writer) error

func (*TernaryOp) FalseExpr

func (op *TernaryOp) FalseExpr() interface{}

func (*TernaryOp) TrueExpr

func (op *TernaryOp) TrueExpr() interface{}

type Translate

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

func NewTranslate

func NewTranslate(v interface{}, children ...Stmt) *Translate

func (*Translate) Add

func (t *Translate) Add(s Stmt) *Translate

func (*Translate) Body

func (t *Translate) Body(children ...Stmt) *Translate

func (*Translate) EmitExpr

func (t *Translate) EmitExpr(ctx *EmitContext, w io.Writer) error

func (*Translate) EmitStmt

func (t *Translate) EmitStmt(ctx *EmitContext, w io.Writer) error

type UnaryOp

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

func NewUnaryOp

func NewUnaryOp(op string, expr interface{}) *UnaryOp

func (*UnaryOp) EmitExpr

func (op *UnaryOp) EmitExpr(ctx *EmitContext, w io.Writer) error

func (*UnaryOp) EmitStmt

func (op *UnaryOp) EmitStmt(ctx *EmitContext, w io.Writer) error

type Union

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

func NewUnion

func NewUnion(children ...Stmt) *Union

func (*Union) Add

func (u *Union) Add(s Stmt) *Union

func (*Union) Body

func (u *Union) Body(s ...Stmt) *Union

func (*Union) EmitStmt

func (op *Union) EmitStmt(ctx *EmitContext, w io.Writer) error

type Use

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

func NewUse

func NewUse(name string) *Use

func (*Use) EmitStmt

func (i *Use) EmitStmt(ctx *EmitContext, w io.Writer) error

type Variable

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

Variable represents a variable in the OpenSCAD language. It can be assigned a value so that in appropriate contexts, an assignment statement is emitted.

func NewVariable

func NewVariable(name string) *Variable

func (*Variable) EmitExpr

func (p *Variable) EmitExpr(ctx *EmitContext, w io.Writer) error

func (*Variable) EmitStmt

func (p *Variable) EmitStmt(ctx *EmitContext, w io.Writer) error

func (*Variable) HasValue

func (p *Variable) HasValue() bool

func (*Variable) String

func (p *Variable) String() string

func (*Variable) Value

func (p *Variable) Value(v interface{}) *Variable

type WriteFileOption

type WriteFileOption interface {
	option.Interface
	// contains filtered or unexported methods
}

func WithOutputDir

func WithOutputDir(dir string) WriteFileOption

Jump to

Keyboard shortcuts

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