parser

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2022 License: MIT, MIT Imports: 5 Imported by: 0

Documentation

Overview

Package Parser provides utilities to automate common text file parsing and editing tasks. It is designed to be used with MemFile, the in memory file system.

The main interface is Parser which implements Parse() (string, error):

type Parser interface {
	Parse() (string, error)
}

Once all options are set, Parse does the work and returns the data as a string. Any other file or data handling structures may choose to implement Parser to gain access the functionality of this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToPascal

func ToPascal(in string) string

func ToSnake

func ToSnake(in string) string

Types

type Any

type Any interface{}

Any type of data

type Caser

type Caser interface {
	String() string
	ChangeCase(c Cases)
}

func NewCaseStringer

func NewCaseStringer(c Cases, s string) Caser

type Cases

type Cases byte
const (
	Pascal Cases // NowIsTheTimeForALLGoodMenToComeToTheAidOfTheirCountry.

)

type GetSetter

type GetSetter interface {
	Get(key Any) (value Any, err error)
	Set(key, value Any) (err error)
}

GetSetter implements basic generic get and set methods. May be used to wrap a dictionary, INI config file, TOML file, JSON config file, struct, etc ...

type Option

type Option interface {
	Parse(string) string
}

Option performs a single operation on text data and returns the result.

type Parameter

type Parameter interface {
	Name() string
	Function(name string) Any
}

Parameter stores a single parameter and returns the name, value, and functionality as needed. Any type may be stored as a parameter, including functions that provide custom functionality.

e.g. a parameter named "newline" might return the string that is used as a linebreak in the text.

nl.Name()
// "newline"
nl.Function()
func()  { return "\n" }

a parameter named "upper" might return the function that is used to change text to upper case.

upper.Name()
// "UpperCase"
upper.Function()
func(s string) string { return strings.ToUpper(s) }

type ParseOptioner

type ParseOptioner interface {
	GetSetter
}

type Parser

type Parser interface {
	Parse() (string, error)
}

func NewParser

func NewParser(r io.Reader) (Parser, error)

type ParserFunctionMap

type ParserFunctionMap map[string]func()

type ParserOptions

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

ParserOptions contains the configuration information for the Parser.

These fields are only used if the behavior is desired, otherwise they should not be set.

If lineseps are provided, they will be converted to the default linesep (or nl if it is given)

type StringFunction

type StringFunction = func(s string) string

StringFunction takes a string and returns a string

Jump to

Keyboard shortcuts

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