mkvisitor

command module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2023 License: MIT Imports: 10 Imported by: 0

README

mkvisitor

Given

package example

type (
	Node struct{}
	Leaf struct{}
)

run mkvisitor -type "Node,Leaf" then generate

package example

import "fmt"

type Visitor interface {
	VisitNode(*Node)
	VisitLeaf(*Leaf)
}

func (s *Node) Accept(v Visitor) { v.VisitNode(s) }
func (s *Leaf) Accept(v Visitor) { v.VisitLeaf(s) }

type VisitorDefault struct{}

func (s *VisitorDefault) VisitNode(_ *Node) {}
func (s *VisitorDefault) VisitLeaf(_ *Leaf) {}
func VisitSwitch(visitor Visitor, v interface{}) {
	switch v := v.(type) {
	case *Node:
		visitor.VisitNode(v)
	case *Leaf:
		visitor.VisitLeaf(v)
	default:
		panic(fmt.Sprintf("VisitSwitch cannot switch %#v", v))
	}
}

in visitor_mkvisitor.go in the same directory.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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