Documentation ¶
Overview ¶
Package parse provides facilities for parsing configuration files.
Index ¶
- Variables
- type Dispenser
- func (d *Dispenser) ArgErr() error
- func (d *Dispenser) Args(targets ...*string) bool
- func (d *Dispenser) EOFErr() error
- func (d *Dispenser) Err(msg string) error
- func (d *Dispenser) Errf(format string, args ...interface{}) error
- func (d *Dispenser) File() string
- func (d *Dispenser) IncrNest()
- func (d *Dispenser) Line() int
- func (d *Dispenser) Next() bool
- func (d *Dispenser) NextArg() bool
- func (d *Dispenser) NextBlock() bool
- func (d *Dispenser) NextLine() bool
- func (d *Dispenser) RemainingArgs() []string
- func (d *Dispenser) SyntaxErr(expected string) error
- func (d *Dispenser) Val() string
- type ServerBlock
Constants ¶
This section is empty.
Variables ¶
var ValidDirectives = make(map[string]struct{})
ValidDirectives is a set of directives that are valid (unordered). Populated by config package's init function.
Functions ¶
This section is empty.
Types ¶
type Dispenser ¶
type Dispenser struct {
// contains filtered or unexported fields
}
Dispenser is a type that dispenses tokens, similarly to a lexer, except that it can do so with some notion of structure and has some really convenient methods.
func NewDispenser ¶
NewDispenser returns a Dispenser, ready to use for parsing the given input.
func NewDispenserTokens ¶
NewDispenserTokens returns a Dispenser filled with the given tokens.
func (*Dispenser) ArgErr ¶
ArgErr returns an argument error, meaning that another argument was expected but not found. In other words, a line break or open curly brace was encountered instead of an argument.
func (*Dispenser) Args ¶
Args is a convenience function that loads the next arguments (tokens on the same line) into an arbitrary number of strings pointed to in targets. If there are fewer tokens available than string pointers, the remaining strings will not be changed and false will be returned. If there were enough tokens available to fill the arguments, then true will be returned.
func (*Dispenser) EOFErr ¶
EOFErr returns an error indicating that the dispenser reached the end of the input when searching for the next token.
func (*Dispenser) File ¶
File gets the filename of the current token. If there is no token loaded, it returns the filename originally given when parsing started.
func (*Dispenser) IncrNest ¶
func (d *Dispenser) IncrNest()
IncrNest adds a level of nesting to the dispenser.
func (*Dispenser) Line ¶
Line gets the line number of the current token. If there is no token loaded, it returns 0.
func (*Dispenser) Next ¶
Next loads the next token. Returns true if a token was loaded; false otherwise. If false, all tokens have been consumed.
func (*Dispenser) NextArg ¶
NextArg loads the next token if it is on the same line. Returns true if a token was loaded; false otherwise. If false, all tokens on the line have been consumed. It handles imported tokens correctly.
func (*Dispenser) NextBlock ¶
NextBlock can be used as the condition of a for loop to load the next token as long as it opens a block or is already in a block. It returns true if a token was loaded, or false when the block's closing curly brace was loaded and thus the block ended. Nested blocks are not supported.
func (*Dispenser) NextLine ¶
NextLine loads the next token only if it is not on the same line as the current token, and returns true if a token was loaded; false otherwise. If false, there is not another token or it is on the same line. It handles imported tokens correctly.
func (*Dispenser) RemainingArgs ¶
RemainingArgs loads any more arguments (tokens on the same line) into a slice and returns them. Open curly brace tokens also indicate the end of arguments, and the curly brace is not included in the return value nor is it loaded.
type ServerBlock ¶ added in v0.8.1
type ServerBlock struct { Addresses []address Tokens map[string][]token }
ServerBlock associates tokens with a list of addresses and groups tokens by directive name.
func ServerBlocks ¶
ServerBlocks parses the input just enough to organize tokens, in order, by server block. No further parsing is performed. If checkDirectives is true, only valid directives will be allowed otherwise we consider it a parse error. Server blocks are returned in the order in which they appear.
func (ServerBlock) HostList ¶ added in v0.8.1
func (sb ServerBlock) HostList() []string
HostList converts the list of addresses that are associated with this server block into a slice of strings, where each address is as it was originally read from the input.