formatter

package
v1.11.2 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alignable

type Alignable interface {
	Align()
	String() string
}

Alignable is an interface that should implements Align() and String() method

type Chunk

type Chunk struct {
	Type ChunkType
	// contains filtered or unexported fields
}

Chunk struct represents a piece of expression token

type ChunkBuffer

type ChunkBuffer struct {
	// contains filtered or unexported fields
}

ChunkBuffer struct reperesents limited-line chunked string from configration.

func (*ChunkBuffer) Append

func (c *ChunkBuffer) Append(nc *ChunkBuffer)

Append buffers

func (*ChunkBuffer) ChunkedString

func (c *ChunkBuffer) ChunkedString(level, offset int) string

Calculate line-chunked strings

func (*ChunkBuffer) String

func (c *ChunkBuffer) String() string

Get "No" chunked string

func (*ChunkBuffer) Write

func (c *ChunkBuffer) Write(s string, t ChunkType)

Write buffer to buffer with ChunkType

type ChunkState

type ChunkState struct {
	// contains filtered or unexported fields
}

ChunkState represents generating chunk strings

type ChunkType

type ChunkType int
const (
	Token ChunkType = iota + 1
	Comment
	Infix
	Group
	Prefix
)

type Declaration

type Declaration struct {
	Type   DeclarationType
	Name   string
	Buffer string
}

type DeclarationType

type DeclarationType int

DeclarationType represents formatted line name - can present on root scope

const (
	Import DeclarationType = iota + 1
	Include
	Acl
	Backend
	Director
	Table
	Penaltybox
	Ratecounter
	Subroutine
)

type Declarations

type Declarations []*Declaration

func (Declarations) Sort

func (d Declarations) Sort()

type DelclarationPropertyLine

type DelclarationPropertyLine struct {
	Key      string
	Operator string
	Value    string
	Leading  string
	Trailing string
	Offset   int

	EndCharacter string
	// contains filtered or unexported fields
}

DelclarationPropertyLine represents a single line of declaration properties. This struct is used for acl, backend, director, and table properties

type DelclarationPropertyLines

type DelclarationPropertyLines []*DelclarationPropertyLine

Type alias for slice of DelclarationPropertyLine

func (DelclarationPropertyLines) Align

func (l DelclarationPropertyLines) Align()

Implement Alignable interface

func (DelclarationPropertyLines) AlignKey

func (l DelclarationPropertyLines) AlignKey()

Declaration property name will be aligned from configuration so need to implement AlignKey() method to do it

func (DelclarationPropertyLines) Sort

func (l DelclarationPropertyLines) Sort()

DelclarationPropertyLines could be sorted by name alphabetically

func (DelclarationPropertyLines) String

func (l DelclarationPropertyLines) String() string

Implement Alignable interface

type Formatter

type Formatter struct {
	// contains filtered or unexported fields
}

Formatter is struct for formatting input VCL.

func New

func New(conf *config.FormatConfig) *Formatter

Create Formatter pointer

func (*Formatter) Format

func (f *Formatter) Format(vcl *ast.VCL) io.Reader

Do formatting. Note that argument of vcl must be an AST-ed tree that is created by parser package. It means parser should have all information about input VCL (comment, empty lines, etc...) And of course input VCL must have a valid syntax.

type GroupedLines

type GroupedLines struct {
	// Accept Alignable interface in order to append Lines or DelclarationPropertyLines
	Lines []Alignable
}

GroupedLines represents grouped lines "grouped" means that lines are separated by empty line, for example:

set req.http.Foo = "bar"; // group 1 set req.http.Foo = "baz"; // group 1

set req.http.Bar = "bar"; // group 2 set req.http.Bar = "baz"; // group 2

These group should be aligned for each group.

func (*GroupedLines) Align

func (g *GroupedLines) Align()

GroupedLines also satisfies Alignable interface

func (*GroupedLines) String

func (g *GroupedLines) String() string

GroupedLines also satisfies Alignable interface

type Line

type Line struct {
	Buffer   string
	Leading  string
	Trailing string
}

Line represents single-line string including leading/trailing comment string

func (Line) String

func (l Line) String() string

Get Line string

type Lines

type Lines []*Line

Type alias for slice of Line

func (Lines) Align

func (l Lines) Align()

Implements Alignable interface

func (Lines) String

func (l Lines) String() string

Implements Alignable interface

Jump to

Keyboard shortcuts

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