confyg: within.website/confyg Index | Files | Directories

package confyg

import "within.website/confyg"

Index

Package Files

allower.go map_output.go print.go read.go reader.go rule.go

func Format Uses

func Format(f *FileSyntax) []byte

type Allower Uses

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 Uses

type AllowerFunc func(verb string, block bool) bool

AllowerFunc implements Allower for inline definitions.

func (AllowerFunc) Allow Uses

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

Allow implements Allower.

type Comment Uses

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 Uses

type CommentBlock struct {
    Comments
    Start Position
}

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

func (*CommentBlock) Span Uses

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

type Comments Uses

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 Uses

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 Uses

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 Uses

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

A FileSyntax represents an entire go.mod file.

func Parse Uses

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

func (*FileSyntax) Span Uses

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

type LParen Uses

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 Uses

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

type Line Uses

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

A Line is a single line of tokens.

func (*Line) Span Uses

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

type LineBlock Uses

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 Uses

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

type MapConfig Uses

type MapConfig map[string][]string

MapConfig is a simple wrapper around a map.

func (MapConfig) Allow Uses

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

Allow accepts everything.

func (MapConfig) Read Uses

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

type Position Uses

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 Uses

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 Uses

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

type Reader Uses

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 Uses

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

ReaderFunc implements Reader for inline definitions.

func (ReaderFunc) Read Uses

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

Directories

PathSynopsis
flagconfygPackage flagconfyg is a hack around confyg.

Package confyg imports 8 packages (graph) and is imported by 1 packages. Updated 2019-07-01. Refresh now. Tools for package owners.