parser

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContinueFunc

type ContinueFunc func(map[string]string) bool

ContinueFunc is a function that is executed to determine if the parser should continue. The input of a function is the parsed result and if the function returns true the parser will continue, otherwise it will stop

type Parser

type Parser struct {
	// Lines that match this regex will be ignored. Usually used to ignore
	// comments
	Ignore *regexp.Regexp

	// Lines that match this regex will be captured and the captures returned.
	// The capturing groups must be named
	Capture *regexp.Regexp
}

Parser Struct that is capable of parsing single-line files using a regex

func (*Parser) Parse

func (p *Parser) Parse(ctx context.Context, file *os.File) ([]map[string]string, error)

Parse will parse a file's lines. Lines will be first checked to see if they match the Ignore regex, if they do they will be ignored. Else they will be checked against the Capture regex. The function returns a slice where each element is a map of capture group name to captured value

func (*Parser) WithParsedResults

func (p *Parser) WithParsedResults(ctx context.Context, scanner *bufio.Scanner, f ContinueFunc) error

WithParsedResults Executes a ContinueFunc for each parsed result within a given file. It also requires a context to allow the scanning to be cancelled if it is taking too long

Jump to

Keyboard shortcuts

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