Documentation ¶
Index ¶
- Variables
- func ApplyVariableDefinition(gen StatementGenerator, definitions map[string]StatementGenerator) error
- func GenerateRandomInts(count int64, max *big.Int) (randInts []*big.Int, err error)
- func GetPercentages(numbers []*big.Int, max *big.Int) []float64
- func PrintSectionMarker(centeredText string, fillerCharacter rune, totalLength int)
- func SectionMarker(centeredText string, fillerCharacter rune, totalLength int) string
- func UnsetVariables(gen StatementGenerator) ([]string, error)
- type CollectionGen
- func (c *CollectionGen) AddChildren(children ...StatementGenerator) error
- func (c *CollectionGen) Consume() bool
- func (c *CollectionGen) Copy() StatementGenerator
- func (c *CollectionGen) Permutations() *big.Int
- func (c *CollectionGen) PermutationsUint64() (uint64, bool)
- func (c *CollectionGen) Reset()
- func (c *CollectionGen) SetConsumeIterations(count *big.Int)
- func (c *CollectionGen) SetConsumeIterationsFast(count uint64)
- func (c *CollectionGen) SourceString() string
- func (c *CollectionGen) String() string
- type OptionalGen
- func (o *OptionalGen) AddChildren(children ...StatementGenerator) error
- func (o *OptionalGen) Consume() bool
- func (o *OptionalGen) Copy() StatementGenerator
- func (o *OptionalGen) Permutations() *big.Int
- func (o *OptionalGen) PermutationsUint64() (uint64, bool)
- func (o *OptionalGen) Reset()
- func (o *OptionalGen) SetConsumeIterations(count *big.Int)
- func (o *OptionalGen) SetConsumeIterationsFast(count uint64)
- func (o *OptionalGen) SourceString() string
- func (o *OptionalGen) String() string
- type OrGen
- func (o *OrGen) AddChildren(children ...StatementGenerator) error
- func (o *OrGen) Consume() bool
- func (o *OrGen) Copy() StatementGenerator
- func (o *OrGen) Permutations() *big.Int
- func (o *OrGen) PermutationsUint64() (uint64, bool)
- func (o *OrGen) Reset()
- func (o *OrGen) SetConsumeIterations(count *big.Int)
- func (o *OrGen) SetConsumeIterationsFast(count uint64)
- func (o *OrGen) SourceString() string
- func (o *OrGen) String() string
- type RootFolderLocation
- func (root RootFolderLocation) GetAbsolutePath(relativePath string) string
- func (root RootFolderLocation) MoveRoot(relativePath string) RootFolderLocation
- func (root RootFolderLocation) ReadDir(relativePath string) ([]os.DirEntry, error)
- func (root RootFolderLocation) ReadFile(relativePath string) ([]byte, error)
- func (root RootFolderLocation) ReadFileFromDirectory(relativeDirectoryPath string, fileName string) ([]byte, error)
- func (root RootFolderLocation) WriteFile(relativePath string, data []byte, perm os.FileMode) error
- func (root RootFolderLocation) WriteFileToDirectory(relativeDirectoryPath string, fileName string, data []byte, perm os.FileMode) error
- type StatementGenerator
- type StatementGeneratorStack
- func (sgs *StatementGeneratorStack) AddText(text string)
- func (sgs *StatementGeneratorStack) AddVariable(name string)
- func (sgs *StatementGeneratorStack) ExitOptionalScope() error
- func (sgs *StatementGeneratorStack) ExitParenScope() error
- func (sgs *StatementGeneratorStack) ExitScope() error
- func (sgs *StatementGeneratorStack) Finish() (StatementGenerator, error)
- func (sgs *StatementGeneratorStack) NewOptionalScope()
- func (sgs *StatementGeneratorStack) NewParenScope()
- func (sgs *StatementGeneratorStack) NewScope()
- func (sgs *StatementGeneratorStack) OptionalRepeat(prefix string) error
- func (sgs *StatementGeneratorStack) Or() error
- func (sgs *StatementGeneratorStack) Repeat() error
- type StatementGeneratorStackElement
- type TextGen
- func (t *TextGen) AddChildren(children ...StatementGenerator) error
- func (t *TextGen) Consume() bool
- func (t *TextGen) Copy() StatementGenerator
- func (t *TextGen) Permutations() *big.Int
- func (t *TextGen) PermutationsUint64() (uint64, bool)
- func (t *TextGen) Reset()
- func (t *TextGen) SetConsumeIterations(count *big.Int)
- func (t *TextGen) SetConsumeIterationsFast(count uint64)
- func (t *TextGen) SourceString() string
- func (t *TextGen) String() string
- type Token
- type TokenReader
- type TokenType
- type VariableGen
- func (v *VariableGen) AddChildren(children ...StatementGenerator) error
- func (v *VariableGen) Consume() bool
- func (v *VariableGen) Copy() StatementGenerator
- func (v *VariableGen) Permutations() *big.Int
- func (v *VariableGen) PermutationsUint64() (uint64, bool)
- func (v *VariableGen) Reset()
- func (v *VariableGen) SetConsumeIterations(count *big.Int)
- func (v *VariableGen) SetConsumeIterationsFast(count uint64)
- func (v *VariableGen) SourceString() string
- func (v *VariableGen) String() string
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func ApplyVariableDefinition ¶
func ApplyVariableDefinition(gen StatementGenerator, definitions map[string]StatementGenerator) error
ApplyVariableDefinition applies the given map of variable definitions to the statement generator. This modifies the statement generator, rather than returning a copy.
func GenerateRandomInts ¶
GenerateRandomInts generates a slice of random integers, with each integer ranging from [0, max). The returned slice will be sorted from smallest to largest. If count <= 0 or max <= 0, then they will be set to 1. If count >= max, then the returned slice will contain all incrementing integers [0, max).
func GetPercentages ¶
GetPercentages converts the slice of numbers to percentages. The max defines the number that would equal 100%. All floats will be between [0.0, 100.0], unless the number is not between [0, max].
func PrintSectionMarker ¶
PrintSectionMarker is a convenience function that prints the result of SectionMarker with a newline appended.
func SectionMarker ¶
SectionMarker returns a marker that may be used to denote sections.
For example, SectionMarker("abc", '-', 21) would return:
-------- abc --------
func UnsetVariables ¶
func UnsetVariables(gen StatementGenerator) ([]string, error)
UnsetVariables returns the name of all variables that do not have a definition. Sorted in ascending order.
Types ¶
type CollectionGen ¶
type CollectionGen struct {
// contains filtered or unexported fields
}
CollectionGen is a generator that contains multiple child generators, and will print all of its children.
func Collection ¶
func Collection(children ...StatementGenerator) *CollectionGen
Collection creates a new StatementGenerator representing a CollectionGen.
func (*CollectionGen) AddChildren ¶
func (c *CollectionGen) AddChildren(children ...StatementGenerator) error
AddChildren implements the interface StatementGenerator.
func (*CollectionGen) Consume ¶
func (c *CollectionGen) Consume() bool
Consume implements the interface StatementGenerator.
func (*CollectionGen) Copy ¶
func (c *CollectionGen) Copy() StatementGenerator
Copy implements the interface StatementGenerator.
func (*CollectionGen) Permutations ¶
func (c *CollectionGen) Permutations() *big.Int
Permutations implements the interface StatementGenerator.
func (*CollectionGen) PermutationsUint64 ¶
func (c *CollectionGen) PermutationsUint64() (uint64, bool)
PermutationsUint64 implements the interface StatementGenerator.
func (*CollectionGen) Reset ¶
func (c *CollectionGen) Reset()
Reset implements the interface StatementGenerator.
func (*CollectionGen) SetConsumeIterations ¶
func (c *CollectionGen) SetConsumeIterations(count *big.Int)
SetConsumeIterations implements the interface StatementGenerator.
func (*CollectionGen) SetConsumeIterationsFast ¶
func (c *CollectionGen) SetConsumeIterationsFast(count uint64)
SetConsumeIterationsFast implements the interface StatementGenerator.
func (*CollectionGen) SourceString ¶
func (c *CollectionGen) SourceString() string
SourceString implements the interface StatementGenerator.
func (*CollectionGen) String ¶
func (c *CollectionGen) String() string
String implements the interface StatementGenerator.
type OptionalGen ¶
type OptionalGen struct {
// contains filtered or unexported fields
}
OptionalGen is a generator that will toggle between displaying its children and not displaying its children.
func Optional ¶
func Optional(children ...StatementGenerator) *OptionalGen
Optional creates a new StatementGenerator representing an OptionalGen.
func (*OptionalGen) AddChildren ¶
func (o *OptionalGen) AddChildren(children ...StatementGenerator) error
AddChildren implements the interface StatementGenerator.
func (*OptionalGen) Consume ¶
func (o *OptionalGen) Consume() bool
Consume implements the interface StatementGenerator.
func (*OptionalGen) Copy ¶
func (o *OptionalGen) Copy() StatementGenerator
Copy implements the interface StatementGenerator.
func (*OptionalGen) Permutations ¶
func (o *OptionalGen) Permutations() *big.Int
Permutations implements the interface StatementGenerator.
func (*OptionalGen) PermutationsUint64 ¶
func (o *OptionalGen) PermutationsUint64() (uint64, bool)
PermutationsUint64 implements the interface StatementGenerator.
func (*OptionalGen) Reset ¶
func (o *OptionalGen) Reset()
Reset implements the interface StatementGenerator.
func (*OptionalGen) SetConsumeIterations ¶
func (o *OptionalGen) SetConsumeIterations(count *big.Int)
SetConsumeIterations implements the interface StatementGenerator.
func (*OptionalGen) SetConsumeIterationsFast ¶
func (o *OptionalGen) SetConsumeIterationsFast(count uint64)
SetConsumeIterationsFast implements the interface StatementGenerator.
func (*OptionalGen) SourceString ¶
func (o *OptionalGen) SourceString() string
SourceString implements the interface StatementGenerator.
func (*OptionalGen) String ¶
func (o *OptionalGen) String() string
String implements the interface StatementGenerator.
type OrGen ¶
type OrGen struct {
// contains filtered or unexported fields
}
OrGen is a generator that contains multiple child generators, and will print only one at a time. Consuming will cycle to the next child.
func Or ¶
func Or(children ...StatementGenerator) *OrGen
Or creates a new StatementGenerator representing an OrGen.
func (*OrGen) AddChildren ¶
func (o *OrGen) AddChildren(children ...StatementGenerator) error
AddChildren implements the interface StatementGenerator.
func (*OrGen) Copy ¶
func (o *OrGen) Copy() StatementGenerator
Copy implements the interface StatementGenerator.
func (*OrGen) Permutations ¶
Permutations implements the interface StatementGenerator.
func (*OrGen) PermutationsUint64 ¶
PermutationsUint64 implements the interface StatementGenerator.
func (*OrGen) SetConsumeIterations ¶
SetConsumeIterations implements the interface StatementGenerator.
func (*OrGen) SetConsumeIterationsFast ¶
SetConsumeIterationsFast implements the interface StatementGenerator.
func (*OrGen) SourceString ¶
SourceString implements the interface StatementGenerator.
type RootFolderLocation ¶
type RootFolderLocation struct {
// contains filtered or unexported fields
}
RootFolderLocation is the location of this project's root folder.
func GetRootFolder ¶
func GetRootFolder() (RootFolderLocation, error)
GetRootFolder returns the location of this project's root folder. This is useful to locate relative directories, which will often be read from and written to for generation. It is assumed that this will always be called from within an IDE.
func (RootFolderLocation) GetAbsolutePath ¶
func (root RootFolderLocation) GetAbsolutePath(relativePath string) string
GetAbsolutePath returns the absolute path of the given path, which should be relative to the project's root folder.
func (RootFolderLocation) MoveRoot ¶
func (root RootFolderLocation) MoveRoot(relativePath string) RootFolderLocation
MoveRoot returns a new RootFolderLocation that defines the root at the new path. The parameter should be relative to the current root.
func (RootFolderLocation) ReadDir ¶
func (root RootFolderLocation) ReadDir(relativePath string) ([]os.DirEntry, error)
ReadDir is equivalent to os.ReadDir, except that it uses the root path and the given relative path.
func (RootFolderLocation) ReadFile ¶
func (root RootFolderLocation) ReadFile(relativePath string) ([]byte, error)
ReadFile is equivalent to os.ReadFile, except that it uses the root path and the given relative path.
func (RootFolderLocation) ReadFileFromDirectory ¶
func (root RootFolderLocation) ReadFileFromDirectory(relativeDirectoryPath string, fileName string) ([]byte, error)
ReadFileFromDirectory is similar to ReadFile, except that it takes in a relative path for the directory containing the file, along with the file name to be read. This is purely for convenience, as the same behavior can be accomplished using ReadFile.
func (RootFolderLocation) WriteFile ¶
WriteFile is equivalent to os.WriteFile, except that it uses the root path and the given relative path.
func (RootFolderLocation) WriteFileToDirectory ¶
func (root RootFolderLocation) WriteFileToDirectory(relativeDirectoryPath string, fileName string, data []byte, perm os.FileMode) error
WriteFileToDirectory is similar to WriteFile, except that it takes in a relative path for the directory containing the file, along with the file name to be written. This is purely for convenience, as the same behavior can be accomplished using WriteFile.
type StatementGenerator ¶
type StatementGenerator interface { // AddChildren adds the given children to the generator. Not all generators accept all children, so this may error. AddChildren(child ...StatementGenerator) error // Consume returns true when the generator is able to produce a unique mutation, and false if it is not. Only one // generator should mutate per call, meaning a parent generator should only mutate when its children return false. // If the top-level generator returns false, then all permutations have been created. Consume() bool // SetConsumeIterations is equivalent to calling Copy then Consume the given number of times, without allocating a // new StatementGenerator. This allows you to generate a specific statement efficiently, rather than calling Consume // the given number of times. If the count is <= 0, then the statement will be in its original state (the same state // as a StatementGenerator copy). SetConsumeIterations(count *big.Int) // SetConsumeIterationsFast is the same as SetConsumeIterations, except far more efficient due to using uint64, // however it only works for iteration counts <= MAX_SIZE(uint64). SetConsumeIterationsFast(count uint64) // String returns a string based on the current permutation. String() string // Copy returns a copy of the given generator (along with all of its children) in its original setting. This means // that the copy is in the same state that the target would be in if it had never called Consume. Copy() StatementGenerator // Reset sets the StatementGenerator back to its original state, which would be as though Consume was never called. // This is equivalent to calling SetConsumeIterations(0), albeit slightly more efficient. Reset() // SourceString returns a string that may be used to recreate the StatementGenerator in a Go source file. SourceString() string // Permutations returns the number of unique permutations that the generator can return. Permutations() *big.Int // PermutationsUint64 returns the number of unique permutations that the generator can return. Returns true if the // number fits within an uint64, false if it's larger than an uint64. PermutationsUint64() (uint64, bool) }
StatementGenerator represents a statement, and is able to produce all valid variations of the statement.
func ParseTokens ¶
func ParseTokens(tokens []Token, includeRepetition bool) (StatementGenerator, error)
ParseTokens parses the given tokens into a StatementGenerator.
type StatementGeneratorStack ¶
type StatementGeneratorStack struct {
// contains filtered or unexported fields
}
StatementGeneratorStack handles the creation of a StatementGenerator by contextually applying operations based on the current state of the internal stack whenever calls are made.
func NewStatementGeneratorStack ¶
func NewStatementGeneratorStack() *StatementGeneratorStack
NewStatementGeneratorStack returns a new *StatementGeneratorStack.
func (*StatementGeneratorStack) AddText ¶
func (sgs *StatementGeneratorStack) AddText(text string)
AddText creates a new TextGen at the current depth.
func (*StatementGeneratorStack) AddVariable ¶
func (sgs *StatementGeneratorStack) AddVariable(name string)
AddVariable creates a new VariableGen at the current depth.
func (*StatementGeneratorStack) ExitOptionalScope ¶
func (sgs *StatementGeneratorStack) ExitOptionalScope() error
ExitOptionalScope decrements the depth, writing all elements from the current depth (and all sub depths) to the preceding depth. This will fail if the root of the current depth is not an OptionalGen.
func (*StatementGeneratorStack) ExitParenScope ¶
func (sgs *StatementGeneratorStack) ExitParenScope() error
ExitParenScope decrements the depth, writing all elements from the current depth (and all sub depths) to the preceding depth, while appending an ending Text(")").
func (*StatementGeneratorStack) ExitScope ¶
func (sgs *StatementGeneratorStack) ExitScope() error
ExitScope decrements the depth, writing all elements from the current depth (and all sub depths) to the preceding depth.
func (*StatementGeneratorStack) Finish ¶
func (sgs *StatementGeneratorStack) Finish() (StatementGenerator, error)
Finish returns a StatementGenerator containing all of the generators that have been added. This returns an error if the stack is not at the root depth, as that indicates a missing scope exit, or too many scope entries.
func (*StatementGeneratorStack) NewOptionalScope ¶
func (sgs *StatementGeneratorStack) NewOptionalScope()
NewOptionalScope increases the depth, creating an OptionalGen at the depth root, and adding elements to the sub depth.
func (*StatementGeneratorStack) NewParenScope ¶
func (sgs *StatementGeneratorStack) NewParenScope()
NewParenScope increases the depth, creating a CollectionGen at the depth root, adding Text("(") to the CollectionGen, and adding any new elements to the sub depth.
func (*StatementGeneratorStack) NewScope ¶
func (sgs *StatementGeneratorStack) NewScope()
NewScope increases the depth.
func (*StatementGeneratorStack) OptionalRepeat ¶
func (sgs *StatementGeneratorStack) OptionalRepeat(prefix string) error
OptionalRepeat will add the last StatementGenerator at the current depth to an OptionalGen. If a prefix is given, then it will be added as a TextGen before the repeated generator.
func (*StatementGeneratorStack) Or ¶
func (sgs *StatementGeneratorStack) Or() error
Or will take all items from the current depth and add them to a parent OrGen. Either the previous depth is an OrGen, or the stack will increment the sub depth to insert an OrGen.
func (*StatementGeneratorStack) Repeat ¶
func (sgs *StatementGeneratorStack) Repeat() error
Repeat will add the last StatementGenerator at the current depth to an OptionalGen.
type StatementGeneratorStackElement ¶
type StatementGeneratorStackElement struct {
// contains filtered or unexported fields
}
StatementGeneratorStackElement represents an element within the StatementGeneratorStack.
func NewStatementGeneratorStackElement ¶
func NewStatementGeneratorStackElement(depth int, gens ...StatementGenerator) *StatementGeneratorStackElement
NewStatementGeneratorStackElement returns a new *StatementGeneratorStackElement.
func (*StatementGeneratorStackElement) Append ¶
func (sgse *StatementGeneratorStackElement) Append(child StatementGenerator)
Append adds the given child to this element's collection.
func (*StatementGeneratorStackElement) LastGenerator ¶
func (sgse *StatementGeneratorStackElement) LastGenerator() StatementGenerator
LastGenerator returns the last StatementGenerator contained within its slice.
type TextGen ¶
type TextGen string
TextGen is a generator that returns a simple string.
func (*TextGen) AddChildren ¶
func (t *TextGen) AddChildren(children ...StatementGenerator) error
AddChildren implements the interface StatementGenerator.
func (*TextGen) Copy ¶
func (t *TextGen) Copy() StatementGenerator
Copy implements the interface StatementGenerator.
func (*TextGen) Permutations ¶
Permutations implements the interface StatementGenerator.
func (*TextGen) PermutationsUint64 ¶
PermutationsUint64 implements the interface StatementGenerator.
func (*TextGen) Reset ¶
func (t *TextGen) Reset()
Reset implements the interface StatementGenerator.
func (*TextGen) SetConsumeIterations ¶
SetConsumeIterations implements the interface StatementGenerator.
func (*TextGen) SetConsumeIterationsFast ¶
SetConsumeIterationsFast implements the interface StatementGenerator.
func (*TextGen) SourceString ¶
SourceString implements the interface StatementGenerator.
type Token ¶
Token represents a token in the synopsis. Unlike with traditional lexers, whitespace is tokenized, with multiple token types for differing lengths, as the whitespace has some significance to the definition.
func (Token) CreatesNewScope ¶
CreatesNewScope returns whether the token creates a new scope.
func (Token) ExitsScope ¶
ExitsScope returns whether the token exits the current scope.
func (Token) IsNewStatement ¶
IsNewStatement returns whether the token represents one a long space, which will end a statement
func (Token) IsStandardSpace ¶
IsStandardSpace returns whether the token represents a short or medium space, which will not end a statement.
type TokenReader ¶
type TokenReader struct {
// contains filtered or unexported fields
}
TokenReader may be used to easily read through a collection of tokens generated from a synopsis. Of note, a TokenReader will skip all short and medium spaces, as clients of a reader will only care about statement boundaries.
func NewTokenReader ¶
func NewTokenReader(tokens []Token) *TokenReader
NewTokenReader returns a new *TokenReader created from the given tokens.
func (*TokenReader) Advance ¶
func (reader *TokenReader) Advance()
Advance is equivalent to calling AdvanceBy(1).
func (*TokenReader) AdvanceBy ¶
func (reader *TokenReader) AdvanceBy(n int)
AdvanceBy advances the reader by the given amount. If the amount is greater than the number of remaining tokens, then it advances to the end. Cannot advance backwards.
func (*TokenReader) Next ¶
func (reader *TokenReader) Next() (Token, bool)
Next returns the next token while advancing the reader. Returns false if there are no more tokens.
func (*TokenReader) Peek ¶
func (reader *TokenReader) Peek() (Token, bool)
Peek returns the next token. Does not advance the reader. Returns false if there are no more tokens.
type TokenType ¶
type TokenType uint8
TokenType is the type of the token.
const ( TokenType_Text TokenType = iota TokenType_Variable TokenType_VariableDefinition TokenType_Or TokenType_Repeat TokenType_OptionalRepeat TokenType_ShortSpace TokenType_MediumSpace TokenType_LongSpace TokenType_ParenOpen TokenType_ParenClose TokenType_OptionalOpen TokenType_OptionalClose TokenType_OneOfOpen TokenType_OneOfClose TokenType_EOF )
type VariableGen ¶
type VariableGen struct {
// contains filtered or unexported fields
}
VariableGen represents a variable in the synopsis. Its values are user-configurable if they cannot be deduced from the synopsis.
func Variable ¶
func Variable(name string, child StatementGenerator) *VariableGen
Variable creates a new StatementGenerator representing a VariableGen.
func (*VariableGen) AddChildren ¶
func (v *VariableGen) AddChildren(children ...StatementGenerator) error
AddChildren implements the interface StatementGenerator.
func (*VariableGen) Consume ¶
func (v *VariableGen) Consume() bool
Consume implements the interface StatementGenerator.
func (*VariableGen) Copy ¶
func (v *VariableGen) Copy() StatementGenerator
Copy implements the interface StatementGenerator.
func (*VariableGen) Permutations ¶
func (v *VariableGen) Permutations() *big.Int
Permutations implements the interface StatementGenerator.
func (*VariableGen) PermutationsUint64 ¶
func (v *VariableGen) PermutationsUint64() (uint64, bool)
PermutationsUint64 implements the interface StatementGenerator.
func (*VariableGen) Reset ¶
func (v *VariableGen) Reset()
Reset implements the interface StatementGenerator.
func (*VariableGen) SetConsumeIterations ¶
func (v *VariableGen) SetConsumeIterations(count *big.Int)
SetConsumeIterations implements the interface StatementGenerator.
func (*VariableGen) SetConsumeIterationsFast ¶
func (v *VariableGen) SetConsumeIterationsFast(count uint64)
SetConsumeIterationsFast implements the interface StatementGenerator.
func (*VariableGen) SourceString ¶
func (v *VariableGen) SourceString() string
SourceString implements the interface StatementGenerator.
func (*VariableGen) String ¶
func (v *VariableGen) String() string
String implements the interface StatementGenerator.