printer

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 License: BSD-3-Clause Imports: 11 Imported by: 3

Documentation

Overview

Package printer implements printing of avo files in various formats.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder func(Config) Printer

Builder can construct a printer.

type Config

type Config struct {
	// Command-line arguments passed to the generator. If provided, this will be
	// included in a code generation warning.
	Argv []string

	// Name of the code generator.
	Name string

	// Name of Go package the generated code will belong to.
	Pkg string
}

Config represents general printing configuration.

func NewArgvConfig

func NewArgvConfig() Config

NewArgvConfig constructs a Config from os.Args. The package name is guessed from the current directory.

func NewDefaultConfig

func NewDefaultConfig() Config

NewDefaultConfig produces a config with Name "avo". The package name is guessed from the current directory.

func NewGoRunConfig

func NewGoRunConfig() Config

NewGoRunConfig produces a Config for a generator that's expected to be executed via "go run ...".

func (Config) GeneratedBy

func (c Config) GeneratedBy() string

GeneratedBy returns a description of the code generator.

Example
package main

import (
	"fmt"

	"github.com/mmcloughlin/avo/printer"
)

func main() {
	// Default configuration named "avo".
	cfg := printer.NewDefaultConfig()
	fmt.Println(cfg.GeneratedBy())

	// Name can be customized.
	cfg = printer.Config{
		Name: "mildred",
	}
	fmt.Println(cfg.GeneratedBy())

	// Argv takes precedence.
	cfg = printer.Config{
		Argv: []string{"echo", "hello", "world"},
		Name: "mildred",
	}
	fmt.Println(cfg.GeneratedBy())

}
Output:

avo
mildred
command: echo hello world

func (Config) GeneratedWarning

func (c Config) GeneratedWarning() string

GeneratedWarning returns text for a code generation warning. Conforms to https://golang.org/s/generatedcode.

type Printer

type Printer interface {
	Print(*ir.File) ([]byte, error)
}

Printer can produce output for an avo File.

func NewGoAsm

func NewGoAsm(cfg Config) Printer

NewGoAsm constructs a printer for writing Go assembly files.

func NewStubs

func NewStubs(cfg Config) Printer

NewStubs constructs a printer for writing stub function declarations.

Jump to

Keyboard shortcuts

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