goefmt

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2020 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package goefmt implements an enhanced and reusable formatter for Go source code. The input is a gofmt formatted source code and the output is a simple representation of the code, consisting of lines and spans.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(tokens chan *Token) chan Line

Format formats a tokenized Go source code returning a channel with each line (without the eol character) of the original source code. Each line consists of a sequence of source code spans for each token.

func Scan

func Scan(name string, input []byte) chan *Token

Scan scans the specified Go source file and returns a channel with Token.

The EOF token is not returned, and the last token does not contain the "\n" character.

func TokenClass

func TokenClass(span *Span) []string

TokenClass returns the HTML class for the specified code span.

Types

type Line

type Line []*Span

Line represents a line of Go source code.

func (Line) String

func (l Line) String() string

String implements the Stringer interface.

type Span

type Span struct {
	Token      token.Token
	Code       string
	Whitespace string
}

Span represents a span of Go source code around a token.

func (*Span) String

func (s *Span) String() string

String implements the Stringer interface.

type Token

type Token struct {

	// Code is the token source code.
	// For keywords, identifiers and basic type literals, it is the token
	// literal.
	// For the auto inserted SEMICOLON operator, it is "\n".
	// For operators, it is the operator string representation.
	// For raw strings literals and general comments, carriage return
	// characters ('\r) are discarded.
	Code string
	// Whitespace is white space after the token.
	// It contains only spaces (U+0020), horizontal tabs (U+0009) and newlines
	// (U+000A).
	Whitespace string
	Value      token.Token
	// contains filtered or unexported fields
}

Token represents a Go token and associated source code, including white space.

func (*Token) String

func (t *Token) String() string

String implements the Stringer interface.

Jump to

Keyboard shortcuts

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