printer

package
v0.394.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2021 License: Apache-2.0 Imports: 7 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
	TYPEINDENT        = 12
	MAXLINE           = 80
)

Variables

This section is empty.

Functions

func Action added in v0.84.0

func Action(w io.Writer, a *sysl.Action)

Action prints actions: lookup data

func Application added in v0.84.0

func Application(w io.Writer, a *sysl.Application)

Application prints applications: App:

func Attrs added in v0.84.0

func Attrs(w io.Writer, key string, a *sysl.Attribute, indentNum int, trim bool)

Attrs prints Attributes: @owner="server"

func Call added in v0.84.0

func Call(w io.Writer, c *sysl.Call)

Call prints: AnApp <- AnEndpoint

func Endpoint added in v0.84.0

func Endpoint(w io.Writer, e *sysl.Endpoint)

Endpoint prints endpoints: Endpoint:

func EnumDecl added in v0.84.0

func EnumDecl(w io.Writer, key string, t *sysl.Type)

func GetPatterns

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

func Module added in v0.84.0

func Module(w io.Writer, mod *sysl.Module)

Module Prints a whole module

func NonEnumDecl added in v0.84.0

func NonEnumDecl(w io.Writer, key string, t *sysl.Type)

func Param added in v0.84.0

func Param(w io.Writer, params []*sysl.Param)

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

func Patterns added in v0.84.0

func Patterns(w io.Writer, attrs map[string]*sysl.Attribute)

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

func Return added in v0.84.0

func Return(w io.Writer, r *sysl.Return)

Return prints return statements: return foo <: type

func Statement added in v0.84.0

func Statement(w io.Writer, s *sysl.Statement)

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

func Type added in v0.84.0

func Type(param *sysl.Param) string

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

func TypeDecl added in v0.84.0

func TypeDecl(w io.Writer, key string, t *sysl.Type)

TypeDecl prints Type decelerations: !type Foo:

this <: string

Types

This section is empty.

Jump to

Keyboard shortcuts

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