printer

package
v0.72.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2020 License: Apache-2.0 Imports: 6 Imported by: 1

README

printer

prints out sysl proto data models back to source code; a "reverse parser"

Usage:

package main
import (
"os"

"github.com/spf13/afero"
"github.com/anz-bank/sysl/pkg/printer"
"github.com/anz-bank/sysl/pkg/loader"
"github.com/sirupsen/logrus"
)
func main(){
	// Create Sysl sile in Memory file system
	fs := afero.NewMemMapFs()
	f, _ := fs.Create("/test.sysl")
	f.Write([]byte(`
Server[~yay]:
    !type Foo:
        foo <: sequence of string
    Endpoint(req <: Foo):
		return ok <: Foo
`))

	// Load Module
	module, _, _ := loader.LoadSyslModule("/", "test.sysl", fs,logrus.New())

	// Make a New printer to os.Stdout (io.Writer) and PrintModule
	printer.NewPrinter(os.Stdout).PrintModule(module)
}

And on stdout should print:

Server[~yay]:
    !type Foo:
        foo <: sequence of string
    Endpoint(req <: Foo):
        return ok <: Foo

Documentation

Overview

package printer prints out sysl datamodels back to source code using the Printer struct. Source code does not have complete fidelity, and elements will be printed out in alphabetical order.

Index

Constants

View Source
const (
	APPLICATIONINDENT = 4
	ENDPOINTINDENT    = 8
	MAXLINE           = 80
)

Variables

This section is empty.

Functions

func GetPatterns

func GetPatterns(attrs map[string]*sysl.Attribute) []string

Types

type Printer

type Printer struct {
	io.Writer
}

Printer prints sysl data structures out to source code

func NewPrinter

func NewPrinter(buf io.Writer) *Printer

NewPrinter returns a printer that can be used to print out sysl source code from data structures

func (*Printer) ParamType

func (p *Printer) ParamType(param *sysl.Param) string

ParamType prints: foo(this <: <ParamType>):

func (*Printer) PrintAction

func (p *Printer) PrintAction(a *sysl.Action)

PrintAction prints actions: lookup data

func (*Printer) PrintApplication

func (p *Printer) PrintApplication(a *sysl.Application)

PrintApplication prints applications: App:

func (*Printer) PrintAttrs

func (p *Printer) PrintAttrs(key string, a *sysl.Attribute, indentNum int)

PrintAttrs prints Attributes: @owner="server"

func (*Printer) PrintCall

func (p *Printer) PrintCall(c *sysl.Call)

PrintCall prints: AnApp <- AnEndpoint

func (*Printer) PrintEndpoint

func (p *Printer) PrintEndpoint(e *sysl.Endpoint)

PrintEndpoint prints endpoints: Endpoint:

func (*Printer) PrintModule

func (p *Printer) PrintModule(mod *sysl.Module)

PrintModule Prints a whole module

func (*Printer) PrintParam

func (p *Printer) PrintParam(params []*sysl.Param)

PrintParam prints Parameters: Endpoint(This <: ParamHere):

func (*Printer) PrintPatterns

func (p *Printer) PrintPatterns(attrs map[string]*sysl.Attribute)

Prints patterns in square brackets: [~foo, ~bar]

func (*Printer) PrintReturn

func (p *Printer) PrintReturn(r *sysl.Return)

PrintReturn prints return statements: return foo <: type

func (*Printer) PrintStatement

func (p *Printer) PrintStatement(s *sysl.Statement)

PrintAttrs prints different statements: return string My <- call lookup db

func (*Printer) PrintTypeDecl

func (p *Printer) PrintTypeDecl(key string, t *sysl.Type)

PrintTypeDecl prints Type decelerations: !type Foo:

this <: string

Jump to

Keyboard shortcuts

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