Documentation ¶
Overview ¶
Package ast provides the abstract syntax tree, parser, and everything else in puppetfileparser
Package ast provides the abstract syntax tree, parser, and everything else in puppetfileparser ¶
Package ast provides the abstract syntax tree, parser, and everything else in puppetfileparser
Index ¶
- Variables
- func DataFromString(input string) string
- func DummyPos() lexer.Position
- func MapNamedCaptureGroups(re *regexp.Regexp, input string) map[string]string
- func NewParser() (*participle.Parser, error)
- func SingleMatch(re *regexp.Regexp, input string) string
- func TagFromString(input string) string
- type ByName
- type Comment
- type Forge
- type MetaPair
- type Metadata
- type Module
- func (m *Module) AddProperties(props []string)
- func (m *Module) AddProperty(prop string)
- func (m Module) Checksum() [16]byte
- func (m Module) ChecksumName() [16]byte
- func (m Module) ChecksumProperties() [][][16]byte
- func (m *Module) EditProperty(key, value string)
- func (m Module) GetProperty(key string) *Property
- func (m Module) GetPropertyValue(name string) string
- func (m *Module) NewBareProperty(value string)
- func (m *Module) Sprint() string
- type ModuleMetadata
- type Property
- type Puppetfile
- func (p *Puppetfile) AddComment(location, text string) error
- func (p *Puppetfile) AddModule(slug string, props []string) error
- func (p *Puppetfile) AddModuleMetadata(name string, tag string, data string) error
- func (p *Puppetfile) AddStatement(s *Statement) error
- func (p *Puppetfile) AddStatementAbove(idx int, s *Statement, stmts []*Statement) []*Statement
- func (p Puppetfile) Checksum() [16]byte
- func (p Puppetfile) GetModule(name string) *Module
- func (p Puppetfile) HasModule(name string) (bool, int)
- func (p *Puppetfile) ParseMetadata() error
- func (p *Puppetfile) RemoveComments(stmts []*Statement) []*Statement
- func (p *Puppetfile) RenameModule(name, new string) error
- func (p *Puppetfile) SearchMetaByModuleName(name string) string
- func (p *Puppetfile) SearchModulesByMetaData(data string) []string
- func (p *Puppetfile) SearchModulesByMetaTag(tag string) []string
- func (p *Puppetfile) SortByName() error
- func (p *Puppetfile) Sprint() string
- type Statement
- type StmtByName
- type Value
Constants ¶
This section is empty.
Variables ¶
var PuppetfileLexer = lexer.Must(regex.New(`
Keyword = ^mod
Forge = ^forge
String = '([^']*)'
Int = \d
Char = [[:alpha:]]
Ident = :[A-Za-z0-9_]+
Comment = #.*
Punct = [,@:.]
Assign = (=>)
Whitespace = [\s\t]+
`))
PuppetfileLexer is a custom regex lexer for Puppetfiles
var ReAssignment = regexp.MustCompile(`(?P<Key>:[A-Za-z0-9_]+)\s?=?>?\s?'?(?P<Value>[^\s=>']*)'?`)
ReAssignment is a compiled regular expression for Module properties with assignements. ReAssignment matches should return two named groups, Key and Value.
var ReComment = regexp.MustCompile(`#.*`)
ReComment is a compiled regular expression for Puppetfile comments
var ReForgeURL = regexp.MustCompile(`forge ["']([^"']*)["']`)
ReForgeURL is a compiled regular expression for extracting a Forge URL from a forge line in a Puppetfile.
var ReGitData = regexp.MustCompile(`(?P<Proto>https?|(?:ssh:\/\/)?git)(?::\/\/.*|@.*)`)
ReGitData is a compiled regular expression for parsing Modules' :git property value. ReGitData matches should return a named group Proto. Proto is the protocol used by git. If Proto is "git" or "ssh://git", this means SSH is to be used. The full match is the URI. ReGitData does not validate URLs.
var ReIdent = regexp.MustCompile(`:[A-Za-z0-9_]+`)
ReIdent is a compiled regular expression for Puppetfile symbols
var ReKeyword = regexp.MustCompile(`^mod`)
ReKeyword is a compiled regular expression for the "mod" keyword
var ReMeta = regexp.MustCompile(`#\s?@(?P<Tag>[\w_-]+):\s*(?P<Data>.*)`)
ReMeta is a compiled regular expression for Puppetfile meta tags and data. ReMeta matches should return two named capture groups, Tag and Data.
var ReMetaData = regexp.MustCompile(`#\s?@[\w_-]+:\s*(?P<Data>.*)`)
ReMetaData is a compiled regular expression for Puppetfile meta data
var ReMetaTag = regexp.MustCompile(`#\s?@(?P<Tag>[\w_-]+):.*`)
ReMetaTag is a compiled regular expression for Puppetfile metadata
var ReString = regexp.MustCompile(`'([^']*)'`)
ReString is a compiled regular expression for Puppetfile strings
var ReValidIdent = regexp.MustCompile(`(:latest|:git|:install_path|:ref|:branch|:tag|:commit|:default_branch|:install_path)`)
ReValidIdent is a compiled regular expression used to validate Idents in the Puppetfile.
Functions ¶
func DataFromString ¶
DataFromString parses a given string and returns metadata if present
func MapNamedCaptureGroups ¶
MapNamedCaptureGroups returns a map of named regex capture groups where map[<group name>] = match Param re: A compiled regular expression Param input: A string to evaluate with the regular expression
func NewParser ¶
func NewParser() (*participle.Parser, error)
NewParser creates and returns a Puppetfile parser
func SingleMatch ¶
SingleMatch returns the first matching capture group. Useful for when you only want to return one value from a match. Param re: A compiled regular expression Param inputL A string to evaluate with the regular expression
func TagFromString ¶
TagFromString parses a given string and returns a meta tag if present
Types ¶
type ByName ¶
type ByName []*Module
ByName implements sort.Interface base on the Module struct's Name field
type Comment ¶
Comment holds the text and lexer position of a comment in the AST
type Forge ¶
type Forge struct {
URL string `Forge @String`
}
Forge holds a Forge declaration
type MetaPair ¶
MetaPair holds the actual metadata, all tags with that metadata, and all modules tagged with that metadata.
func PairFromString ¶
PairFromString parses a given string and returns a MetaPair, if possible
type Metadata ¶
type Metadata struct {
MetaPairs []MetaPair
}
Metadata holds an array of MetaPair objects
func (*Metadata) DataExists ¶
DataExists checks if data exists in Metadata and returns the an array of indexs of the data MetaPairs and a boolean if it exists or not. The index return value of non existent data is -1.
func (*Metadata) SearchByData ¶
SearchByData returns all metapairs with the specified data or nil
func (*Metadata) SearchByTag ¶
SearchByTag returns all metapairs with the specified tag or nil
type Module ¶
type Module struct { Pos lexer.Position Name string `Keyword @String","?` Properties []*Property `( @@ )*` }
Module Struct that holds each Module and related properties
func (*Module) AddProperties ¶
AddProperties accepts strings in the form of "key=>value", parses them into Property objects, and adds them to the module. Key must have a ":" prefixing it, just like in a Puppetfile.
func (*Module) AddProperty ¶
AddProperty accepts a string and adds it as a property to the module. AddProperty is used to add special properties (bare version string / :latest symbol)
func (Module) ChecksumName ¶
ChecksumName returns an md5 checksum of the Module Name
func (Module) ChecksumProperties ¶
ChecksumProperties returns an array of [k, v] arrays where k = Property Key field checksum and v= Property Value field checksum.
func (*Module) EditProperty ¶
EditProperty overwrites the value of an existing property
func (Module) GetProperty ¶
GetProperty returns a pointer to a Property of the module, if the Module has said property. GetProperty performs this search by Property key.
func (Module) GetPropertyValue ¶
GetPropertyValue accepts a string of a param name and returns the associated value if present. As Puppetfiles are distinctly idomatic, there are some inputs that can potentially match several values: Input "version": Returns a bare version string, the :latest
symbol as a string, :tag, or :ref if :ref is a semver.
Input "branch": Returns :branch, :default_branch, or :ref
if :ref is a git branch.
func (*Module) NewBareProperty ¶
NewBareProperty overwrites all other properties in a module with a single bare property.
type ModuleMetadata ¶
ModuleMetadata holds the module name and all the metadata assigned to the module.
func (*ModuleMetadata) SearchByData ¶
func (m *ModuleMetadata) SearchByData(data string) []MetaPair
SearchByData returns all metapairs with the specified data or nil
func (*ModuleMetadata) SearchByTag ¶
func (m *ModuleMetadata) SearchByTag(tag string) []MetaPair
SearchByTag returns all metapairs with the specified tag or nil
type Property ¶
Property Struct that hold key-value properties pairs
func (Property) ChecksumKey ¶
ChecksumKey returns the md5 checksum of the Key field
func (Property) ChecksumValue ¶
ChecksumValue returns the md5 checksum of the Value field
func (*Property) OverwriteValue ¶
OverwriteValue creates a new *Value adds it to the Property Value field.
type Puppetfile ¶
type Puppetfile struct { Forge *Forge `( @@ )?` Statements []*Statement `{ @@ }` Metadata Metadata ModuleMetadata []ModuleMetadata TopBlockComments []*Statement BottomBlockComments []*Statement ModuleVersionMap map[string]string }
Puppetfile Struct that holds entire Puppetfile
func Parse ¶
func Parse(text string) (*Puppetfile, error)
Parse parses a Puppetfile and returns the parsed AST
func (*Puppetfile) AddComment ¶
func (p *Puppetfile) AddComment(location, text string) error
AddComment adds a Comment to either the top or bottom block comments
func (*Puppetfile) AddModule ¶
func (p *Puppetfile) AddModule(slug string, props []string) error
AddModule adds a module and its properties to the Puppetfile
func (*Puppetfile) AddModuleMetadata ¶
func (p *Puppetfile) AddModuleMetadata(name string, tag string, data string) error
AddModuleMetadata adds a new metadata statement above a module in the Puppetfile
func (*Puppetfile) AddStatement ¶
func (p *Puppetfile) AddStatement(s *Statement) error
AddStatement appends a Statement the Puppetfiles Statements property and sorts Statements
func (*Puppetfile) AddStatementAbove ¶
func (p *Puppetfile) AddStatementAbove(idx int, s *Statement, stmts []*Statement) []*Statement
AddStatementAbove adds a Statement to a slice of Statements above the given index
func (Puppetfile) Checksum ¶
func (p Puppetfile) Checksum() [16]byte
Checksum returns an md5 checksum of the stringified contents of Puppetfile
func (Puppetfile) GetModule ¶
func (p Puppetfile) GetModule(name string) *Module
GetModule returns a Module struct by name
func (Puppetfile) HasModule ¶
func (p Puppetfile) HasModule(name string) (bool, int)
HasModule returns true if the named module exists in the Puppetfile
func (*Puppetfile) ParseMetadata ¶
func (p *Puppetfile) ParseMetadata() error
ParseMetadata goes through all statements in the Puppetfile and makes metadata to module associations. It then populates the module's Metadata field.
func (*Puppetfile) RemoveComments ¶
func (p *Puppetfile) RemoveComments(stmts []*Statement) []*Statement
RemoveComments removes all Statements from the Puppetfile that have a Comment
func (*Puppetfile) RenameModule ¶
func (p *Puppetfile) RenameModule(name, new string) error
RenameModule renames a module in the Puppetfile while keeping the module's properties the same. The Puppetfile is then sorted by name.
func (*Puppetfile) SearchMetaByModuleName ¶
func (p *Puppetfile) SearchMetaByModuleName(name string) string
SearchMetaByModuleName returns a string of all metadata for the given module name
func (*Puppetfile) SearchModulesByMetaData ¶
func (p *Puppetfile) SearchModulesByMetaData(data string) []string
SearchModulesByMetaData returns a slice of module name strings that have the given metadata associated with them.
func (*Puppetfile) SearchModulesByMetaTag ¶
func (p *Puppetfile) SearchModulesByMetaTag(tag string) []string
SearchModulesByMetaTag returns a slice of module name strings that have the given tag associated with them.
func (*Puppetfile) SortByName ¶
func (p *Puppetfile) SortByName() error
SortByName reorders all Statements to be sorted alphabetically by name. Comment statements are reordered based on their original positions relative to the modules below them in the Puppetfile.
func (*Puppetfile) Sprint ¶
func (p *Puppetfile) Sprint() string
Sprint returns string representation of type
type Statement ¶
Statement holds statements that make up the Puppetfile, either modules or comments
func DummyComment ¶
func DummyComment() *Statement
DummyComment returns a Statement pointer with a dummy Comment field
func DummyModule ¶
func DummyModule() *Statement
DummyModule returns a Statement pointer with a dummy Module field
func DummyStatement ¶
func DummyStatement() *Statement
DummyStatement returns a Statement pointer with nil fields
type StmtByName ¶
type StmtByName []*Statement
StmtByName implements sort.Interface base on slice of Statements base on Module field's Name field
func (StmtByName) Len ¶
func (a StmtByName) Len() int
func (StmtByName) Less ¶
func (a StmtByName) Less(i, j int) bool
func (StmtByName) Swap ¶
func (a StmtByName) Swap(i, j int)