parse

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// MinuteParser is a parser to parse the minute component of a cron expression
	MinuteParser = NewParser(numberer.MinuteFactory)

	// HourParser is a parser to parse the hour component of a cron expression
	HourParser = NewParser(numberer.HourFactory)

	// DayOfMonthParser is a parser to parse the day of month component of a cron expression
	DayOfMonthParser = NewParser(numberer.DayOfMonthFactory)

	// MonthParser is a parser to parse the month component of a cron expression
	MonthParser = NewParser(numberer.MonthFactory)

	// DayOfWeekParser is a parser to parse the day of week component of a cron expression
	DayOfWeekParser = NewParser(numberer.DayOfWeekFactory)
)

Functions

This section is empty.

Types

type Adapter

type Adapter struct {
	PartsFactory    PartsProvider
	NumbererFactory NumbererProvider
}

Adapter is a type that can adapt the PartsProvider and the Provider into a Parser

func NewAdapter

func NewAdapter(provider NumbererProvider) Adapter

NewAdapter will return you a new instance of an Adapter, with a Partitioner as its PartsFactory

func (Adapter) Parse

func (a Adapter) Parse(statement string) (Numberer, error)

Parse implements Parser and will parse the statement into a Numberer, by parsing it into parts, and then into an AggregateNumberer

type AggregateNumberer

type AggregateNumberer []Numberer

AggregateNumberer is a Numberer that will grab values from all of the contained numberers combining them

func (AggregateNumberer) Numbers

func (a AggregateNumberer) Numbers() []int

Numbers implements the Numberer interface and will produce an ordered, de-duplicated list of all of the numbers contained within the AggregateNumberer

type BaseNumbererFactory

type BaseNumbererFactory struct {
	Factory numberer.Provider
}

BaseNumbererFactory is a type that wraps numberer.Provider and will return the correct numberer for a given parsed part

func NewBaseNumbererFactory

func NewBaseNumbererFactory(factory numberer.Provider) BaseNumbererFactory

NewBaseNumbererFactory is a type that can give you a new instance of the BaseNumbererFactory

func (BaseNumbererFactory) Numberer

func (b BaseNumbererFactory) Numberer(parts Part) (Numberer, error)

Numberer implements the Provider interface and will provide the correct Numberer based on pattern matching specific patterns of tokens

type Numberer

type Numberer interface {
	Numbers() []int
}

Numberer is an interface that represents the ability to get a set of numbers from a statement/numberer of a statement

func NewStepNumberer

func NewStepNumberer(base Numberer, stepStr string) (Numberer, error)

NewStepNumberer will return a Numberer that will only output numbers in steps from the Numberer that it decorates

type NumbererProvider

type NumbererProvider interface {
	Numberer(parts Part) (Numberer, error)
}

NumbererProvider is a type that represents a type that can give you numbers for a numberer

type Parser

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

Parser is the interface that represents a type that can parse numberer of a cron statement into a Numberer

func NewParser

func NewParser(provider numberer.Provider) Parser

NewParser will return you a new parser for a given numberer.Provider

type Part

type Part []Token

Part is a group of tokens, that represent a single item, within a field of a cron expression, e.g. (0-30/5) within an a field like "0-30/5,40,50"

func (Part) Types

func (p Part) Types() Types

Types returns you the types of all of the statement types contained within a pary

type Partitioner

type Partitioner struct {
	TokenSource func(input string) TokenSource
}

Partitioner is a type that adapts a Tokeniser into a list of Parts

func NewPartitioner

func NewPartitioner() Partitioner

NewPartitioner is a type that can parse a field of a cron statement into it's constituent parts

func (Partitioner) Parts

func (p Partitioner) Parts(input string) ([]Part, error)

Parts will read all of the tokens from the Tokeniser and will split them based on the commas in the input into their parts

type PartsProvider

type PartsProvider interface {
	Parts(input string) ([]Part, error)
}

PartsProvider is an interface that represents a type that can parse a field of a cron expression into it's constituent parts

type StateFunc

type StateFunc func(t *Tokeniser) StateFunc

StateFunc is a function that represents a specific state within the state machine

type StepNumberer

type StepNumberer struct {
	Base Numberer
	Step int
}

StepNumberer is a type that decorates Numberer, and only returns values from the base if they are in the step of the Step member

func (StepNumberer) Numbers

func (s StepNumberer) Numbers() []int

Numbers implements Numberer and will return the number only if step mod index == 0

type StepNumbererFactory

type StepNumbererFactory struct {
	Base NumbererProvider
}

StepNumbererFactory is a decorator of a Provider

func NewStepNumbererFactory

func NewStepNumbererFactory(base NumbererProvider) StepNumbererFactory

NewStepNumbererFactory will create a new instance of StepNumbererFactory wrapping a base factory

func (StepNumbererFactory) Numberer

func (s StepNumbererFactory) Numberer(part Part) (Numberer, error)

Numberer implements Provider and will return a StepNumberer if the part contains a step, otherwise it will return the base

type Token

type Token struct {
	Type  TokenType
	Value string
}

Token is a single token emitted from the state machine

type TokenSource

type TokenSource interface {
	Tokens() chan Token
}

TokenSource is an interface that represents a type that can emmit a stream of tokens

func NewTokenSource

func NewTokenSource(input string) TokenSource

NewTokenSource will return, and start the Tokeniser for a given input string

type TokenType

type TokenType int

TokenType is a type that represents the type of a value within the field of a cron statement

const (
	TokenTypeError TokenType = iota
	TokenTypeAny
	TokenTypeComma
	TokenTypeDash
	TokenTypeSlash
	TokenTypeNumber
)

Types of tokens in a cron expression

func (TokenType) String

func (t TokenType) String() string

String implements fmt.Stringer returning a string representation of the type of token

type Tokeniser

type Tokeniser struct {
	Input             string
	Start, Pos, Width int

	StartState StateFunc
	// contains filtered or unexported fields
}

Tokeniser is a type that provides utilities for creating a state machine to tokenise an input string

func NewTokeniser

func NewTokeniser(input string) *Tokeniser

NewTokeniser will return a new *Tokeniser with the start state as lexField

func (*Tokeniser) AcceptNumber

func (t *Tokeniser) AcceptNumber()

AcceptNumber will call next for as long as the rune is a numeric value

func (*Tokeniser) Backup

func (t *Tokeniser) Backup()

Backup will move back one character in the input stream

func (*Tokeniser) Emit

func (t *Tokeniser) Emit(typ TokenType)

Emit will emit a token of the given type, and set the start of the current section to the current position

func (*Tokeniser) Errorf

func (t *Tokeniser) Errorf(format string, args ...interface{}) StateFunc

Errorf will return an error token, and will return nil as a StateFunc, ending tokenisation

func (*Tokeniser) Next

func (t *Tokeniser) Next() rune

Next will move to the next rune in the input string

func (*Tokeniser) Run

func (t *Tokeniser) Run()

Run will run the Tokeniser until the state returned is nil

func (*Tokeniser) Tokens

func (t *Tokeniser) Tokens() chan Token

Tokens implements the TokenSource interface an returns the channel that Tokens will be streamed out on

type Types

type Types []TokenType

Types is a slice of token types, allows methods to be added to allow for pattern matching different sequences of tokens

func (Types) Contains

func (t Types) Contains(search TokenType) bool

Contains tells you whether a specific TokenType is contained within this array of types

func (Types) StartsWith

func (t Types) StartsWith(typ TokenType) bool

StartsWith tells you whether the first type within a slice of TokenTypes is the same as the type provided

Jump to

Keyboard shortcuts

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