format

package
v0.19.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package format implements pretty printers for TTCN-3 source code.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fprint

func Fprint(w io.Writer, src interface{}) error

Fprint formats src in canonical TTCN-3 style and writes the result to w or returns an (I/O or syntax) error. src is expected to be syntactically correct TTCN-3 source text.

Example
package main

import (
	"os"

	"github.com/nokia/ntt/ttcn3/format"
)

func main() {
	input := "p :=  {\n x:=1, // Comment\ny := 234 // Comment 2\n}"
	if err := format.Fprint(os.Stdout, input); err != nil {
		panic(err)
	}
}
Output:

p := {
	x := 1,  // Comment
	y := 234 // Comment 2
}

Types

type CanonicalPrinter

type CanonicalPrinter struct {
	// UseSpaces controls whether to use spaces instead of tabs for indenting.
	UseSpaces bool

	// TabWidth is the width of a tab character (equivalent to the number
	// of spaces, default is 8).
	TabWidth int

	// Indent is the level of indentation at which to start.
	Indent int
	// contains filtered or unexported fields
}

CanonicalPrinter is a simple formatter that only fixes indentation and various whitespace issues.

Example
package main

import (
	"os"

	"github.com/nokia/ntt/ttcn3/format"
)

func main() {
	input := "p := {\n x:=1, // Comment\ny := 234 // Comment 2\n}"
	p := format.NewCanonicalPrinter(os.Stdout)
	p.Indent = 1
	p.UseSpaces = true
	p.TabWidth = 2
	p.Fprint(input)
}
Output:

  p := {
    x := 1,  // Comment
    y := 234 // Comment 2
  }

func NewCanonicalPrinter

func NewCanonicalPrinter(w io.Writer) *CanonicalPrinter

NewCanonicalPrinter returns a new printer that formats source code.

func (*CanonicalPrinter) Fprint

func (p *CanonicalPrinter) Fprint(v interface{}) error

Jump to

Keyboard shortcuts

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