Back to godoc.org
within.website/confyg

Package confyg

v1.1.0
Latest Go to latest
Published: Dec 13, 2019 | License: BSD-3-Clause | Module: within.website/confyg

Index

Package Files

func Format

func Format(f *FileSyntax) []byte

type Allower

type Allower interface {
	Allow(verb string, block bool) bool
}

Allower defines if a given verb and block combination is valid for configuration parsing.

If this is intended to be a statement-like verb, block should be set to false. If this is intended to be a block-like verb, block should be set to true.

type AllowerFunc

type AllowerFunc func(verb string, block bool) bool

AllowerFunc implements Allower for inline definitions.

func (AllowerFunc) Allow

func (a AllowerFunc) Allow(verb string, block bool) bool

Allow implements Allower.

type Comment

type Comment struct {
	Start  Position
	Token  string // without trailing newline
	Suffix bool   // an end of line (not whole line) comment
}

A Comment represents a single // comment.

type CommentBlock

type CommentBlock struct {
	Comments
	Start Position
}

A CommentBlock represents a top-level block of comments separate from any rule.

func (*CommentBlock) Span

func (x *CommentBlock) Span() (start, end Position)

type Comments

type Comments struct {
	Before []Comment // whole-line comments before this expression
	Suffix []Comment // end-of-line comments after this expression

	// For top-level expressions only, After lists whole-line
	// comments following the expression.
	After []Comment
}

Comments collects the comments associated with an expression.

func (*Comments) Comment

func (c *Comments) Comment() *Comments

Comment returns the receiver. This isn't useful by itself, but a Comments struct is embedded into all the expression implementation types, and this gives each of those a Comment method to satisfy the Expr interface.

type Expr

type Expr interface {
	// Span returns the start and end position of the expression,
	// excluding leading or trailing comments.
	Span() (start, end Position)

	// Comment returns the comments attached to the expression.
	// This method would normally be named 'Comments' but that
	// would interfere with embedding a type of the same name.
	Comment() *Comments
}

An Expr represents an input element.

type FileSyntax

type FileSyntax struct {
	Name string // file path
	Comments
	Stmt []Expr
}

A FileSyntax represents an entire go.mod file.

func Parse

func Parse(file string, data []byte, r Reader, al Allower) (*FileSyntax, error)

func (*FileSyntax) Span

func (x *FileSyntax) Span() (start, end Position)

type LParen

type LParen struct {
	Comments
	Pos Position
}

An LParen represents the beginning of a parenthesized line block. It is a place to store suffix comments.

func (*LParen) Span

func (x *LParen) Span() (start, end Position)

type Line

type Line struct {
	Comments
	Start Position
	Token []string
	End   Position
}

A Line is a single line of tokens.

func (*Line) Span

func (x *Line) Span() (start, end Position)

type LineBlock

type LineBlock struct {
	Comments
	Start  Position
	LParen LParen
	Token  []string
	Line   []*Line
	RParen RParen
}

A LineBlock is a factored block of lines, like

require (
	"x"
	"y"
)

func (*LineBlock) Span

func (x *LineBlock) Span() (start, end Position)

type MapConfig

type MapConfig map[string][]string

MapConfig is a simple wrapper around a map.

func (MapConfig) Allow

func (mc MapConfig) Allow(verb string, block bool) bool

Allow accepts everything.

func (MapConfig) Read

func (mc MapConfig) Read(errs *bytes.Buffer, fs *FileSyntax, line *Line, verb string, args []string)

type Position

type Position struct {
	Line     int // line in input (starting at 1)
	LineRune int // rune in line (starting at 1)
	Byte     int // byte in input (starting at 0)
}

A Position describes the position between two bytes of input.

type RParen

type RParen struct {
	Comments
	Pos Position
}

An RParen represents the end of a parenthesized line block. It is a place to store whole-line (before) comments.

func (*RParen) Span

func (x *RParen) Span() (start, end Position)

type Reader

type Reader interface {
	Read(errs *bytes.Buffer, fs *FileSyntax, line *Line, verb string, args []string)
}

Reader is called when individual lines of the configuration file are being read. This is where you should populate any relevant structures with information.

If something goes wrong in the file parsing step, add data to the errs buffer describing what went wrong.

type ReaderFunc

type ReaderFunc func(errs *bytes.Buffer, fs *FileSyntax, line *Line, verb string, args []string)

ReaderFunc implements Reader for inline definitions.

func (ReaderFunc) Read

func (r ReaderFunc) Read(errs *bytes.Buffer, fs *FileSyntax, line *Line, verb string, args []string)
Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier