Documentation ¶
Overview ¶
Package atom provides primitives to describe and get the properties of an atomic part of a PKGBUILD file.
A PKGBUILD can contain:
- Blank lines,
- Comment lines,
- Variable declarations (with distinction between string & array variables) containing themselves a name and a list of values and inner comments,
- Function declarations containing themselves a name and a body,
- Trailing comments after variables/functions declarations.
There should be only one root atom on a line of the file. For this reason, declarations and trailing comments are grouped in an atom of type group.
Index ¶
- func Debug(a Atom) string
- func GetBegin(a Atom) position.Position
- func GetEnd(a Atom) position.Position
- func IncrementPosition(a Atom, inc position.Increment, recursive ...bool) (newBegin, newEnd position.Position)
- func MoveAtom(a Atom, begin position.Position, recursive ...bool) (newBegin, newEnd position.Position)
- func RecomputeAllPositions(a Atom, optBegin ...position.Position) (newBegin, newEnd position.Position)
- func RecomputePosition(a Atom, optBegin ...position.Position) (newBegin, newEnd position.Position)
- func SetBegin(a Atom, b position.Position) position.Position
- func SetEnd(a Atom, e position.Position) position.Position
- type Atom
- type AtomCheckerFunc
- type AtomFunc
- func (a *AtomFunc) Clone() Atom
- func (a *AtomFunc) Copy() *AtomFunc
- func (a *AtomFunc) FormatSpaces(recomputeRaw bool)
- func (a *AtomFunc) GetBody() string
- func (a *AtomFunc) GetBodyPositions() (b, e position.Position)
- func (a AtomFunc) GetName() string
- func (a AtomFunc) GetNamePositions() (b, e position.Position)
- func (a *AtomFunc) RecomputeRaw()
- func (a *AtomFunc) SetBody(b string)
- func (a *AtomFunc) SetBodyPositions(b, e position.Position)
- func (a AtomFunc) SetName(n string)
- func (a AtomFunc) SetNamePositions(b, e position.Position)
- type AtomGroup
- func (a *AtomGroup) Clone() Atom
- func (a *AtomGroup) Copy() *AtomGroup
- func (a *AtomGroup) FormatSpaces(recomputeRaw bool)
- func (a AtomGroup) GetPositions() (b, e position.Position)
- func (a AtomGroup) GetRaw() string
- func (a AtomGroup) GetType() AtomType
- func (a *AtomGroup) RecomputRaw()
- func (a AtomGroup) SetPositions(b, e position.Position)
- func (a AtomGroup) SetRaw(r string)
- func (a AtomGroup) SetType(t AtomType)
- type AtomNamed
- type AtomType
- type AtomValue
- func (a *AtomValue) Clone() Atom
- func (a *AtomValue) Copy() *AtomValue
- func (a *AtomValue) GetDepends() []string
- func (a *AtomValue) GetFormatted(quoteNeeded bool) string
- func (a *AtomValue) GetParsed(depends map[string]string) string
- func (a AtomValue) GetPositions() (b, e position.Position)
- func (a AtomValue) GetRaw() string
- func (a AtomValue) GetType() AtomType
- func (a *AtomValue) GetValue() string
- func (a *AtomValue) SetFormat(f ValueFormatter)
- func (a AtomValue) SetPositions(b, e position.Position)
- func (a AtomValue) SetRaw(r string)
- func (a AtomValue) SetType(t AtomType)
- type AtomVar
- func (a *AtomVar) Clone() Atom
- func (a *AtomVar) Copy() *AtomVar
- func (a *AtomVar) FormatSpaces(recomputeRaw bool)
- func (a *AtomVar) FormatVariables(recomputeRaw, quoteNeeded bool, optType ...AtomType)
- func (a *AtomVar) GetArrayFormatted(quoteNeeded bool) []string
- func (a *AtomVar) GetArrayParsed(depends map[string]string) []string
- func (a *AtomVar) GetArrayValue() []string
- func (a *AtomVar) GetDepends() map[string]bool
- func (a AtomVar) GetName() string
- func (a AtomVar) GetNamePositions() (b, e position.Position)
- func (a *AtomVar) GetStringFormatted(quoteNeeded bool) string
- func (a *AtomVar) GetStringParsed(depends map[string]string) string
- func (a *AtomVar) GetStringValue() string
- func (a *AtomVar) GetValue() (e *AtomValue, exists bool)
- func (a *AtomVar) GetValues() []*AtomValue
- func (a *AtomVar) RecomputRaw()
- func (a *AtomVar) RemoveComments(recomputeRaw bool)
- func (a AtomVar) SetName(n string)
- func (a AtomVar) SetNamePositions(b, e position.Position)
- func (a *AtomVar) SetValues(values ...Atom)
- type Info
- func (i *Info) ArrayRawValue() []string
- func (i *Info) ArrayValue() []string
- func (i *Info) Begin() position.Position
- func (i *Info) Body() string
- func (i *Info) End() position.Position
- func (i *Info) Function() (n *AtomFunc, ok bool)
- func (i *Info) Index() int
- func (i *Info) IsArrayVar() bool
- func (i *Info) IsFunc() bool
- func (i *Info) IsStringVar() bool
- func (i *Info) IsVar() bool
- func (i *Info) Name() string
- func (i *Info) Raw() string
- func (i *Info) StringRawValue() string
- func (i *Info) StringValue() string
- func (i *Info) Variable() (n *AtomVar, ok bool)
- type InfoList
- func (l *InfoList) Filter(cb NamedCheckerFunc) []*Info
- func (l *InfoList) FilterFirst(cb NamedCheckerFunc) (info *Info, exists bool)
- func (l *InfoList) Functions() []*Info
- func (l *InfoList) Get(a Atom) (info *Info, exists bool)
- func (l *InfoList) GetByIndex(idx int) (info *Info, exists bool)
- func (l *InfoList) GetDeep(a Atom) (info *Info, exists bool)
- func (l *InfoList) GetNamed(n AtomNamed) (info *Info, exists bool)
- func (l *InfoList) GetValue(name string) string
- func (l *InfoList) GetValues() map[string]string
- func (l *InfoList) HasValue(name string) bool
- func (l *InfoList) Keys() Slice
- func (l *InfoList) RecomputeValues()
- func (l *InfoList) Update(a Atom, i int) (t rune)
- func (l *InfoList) UpdateAll(atoms Slice)
- func (l *InfoList) Variables() []*Info
- type NamedCheckerFunc
- type Slice
- func (l Slice) Clone() Slice
- func (l Slice) Filter(types ...AtomType) Slice
- func (l Slice) FilterFirst(types ...AtomType) (Atom, bool)
- func (l Slice) FilterFirstRecursive(types ...AtomType) (Atom, bool)
- func (l Slice) FilterRecursive(types ...AtomType) Slice
- func (l *Slice) Insert(idx int, atoms ...Atom)
- func (l Slice) Map(cb func(Atom) Atom) Slice
- func (l *Slice) Pop() (a Atom, exists bool)
- func (l *Slice) PopFront() (a Atom, exists bool)
- func (l *Slice) Push(atoms ...Atom)
- func (l *Slice) PushFront(atoms ...Atom)
- func (l *Slice) Remove(idx int) (a Atom, exists bool)
- func (l Slice) Search(cb AtomCheckerFunc, optRecursive ...bool) (result Slice)
- func (l Slice) SearchFirst(cb AtomCheckerFunc, optRecursive ...bool) (result Atom, exists bool)
- type TypeSet
- type ValueElement
- type ValueFormatter
- func (f ValueFormatter) Clone() ValueFormatter
- func (f ValueFormatter) Debug() string
- func (f ValueFormatter) Format(q rune) string
- func (f ValueFormatter) GetDepends() (depends []string)
- func (f ValueFormatter) HasDep() bool
- func (f ValueFormatter) Parse(depends map[string]string) string
- func (f ValueFormatter) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IncrementPosition ¶
func IncrementPosition(a Atom, inc position.Increment, recursive ...bool) (newBegin, newEnd position.Position)
IncrementPosition moves the given atom in incrementing the beginning and the end positions with the given increment. If recursive is needed, it moves the inner atoms too. It returns the new begin/end positions of the atom.
func MoveAtom ¶
func MoveAtom(a Atom, begin position.Position, recursive ...bool) (newBegin, newEnd position.Position)
MoveAtom moves the atom to the given position. If recursive is needed, it moves the inner atoms too. It returns the new begin/end positions of the atom.
func RecomputeAllPositions ¶
func RecomputeAllPositions(a Atom, optBegin ...position.Position) (newBegin, newEnd position.Position)
RecomputeAllPositions is same as RecomputePosition but it recomputes the inner atoms too. It returns the new begin/end positions of the atom.
func RecomputePosition ¶
RecomputePosition recomputes the end position of the atom according to the raw string. If a begin position is given, it moves the atom first before recomputing. It returns the new begin/end positions of the atom.
Types ¶
type Atom ¶
type Atom interface { GetType() AtomType GetRaw() string GetPositions() (begin, end position.Position) SetType(AtomType) SetRaw(string) SetPositions(begin, end position.Position) Clone() Atom }
Atom represents an atomic part of a PKGBUILD.
type AtomCheckerFunc ¶
func AtomCheckAll ¶
func AtomCheckAll(checkers ...AtomCheckerFunc) AtomCheckerFunc
AtomCheckAll returns a callback checker which applies all given checkers.
func NewMatcher ¶
func NewMatcher(types ...AtomType) AtomCheckerFunc
NewMatcher returns a callback checking if an atom has a supported type.
func NewRevMatcher ¶
func NewRevMatcher(types ...AtomType) AtomCheckerFunc
NewRevMatcher returns a callback checking if an atom has not a supported type.
func RevCheck ¶
func RevCheck(cb AtomCheckerFunc) AtomCheckerFunc
RevCheck returns the inverse of the given callback.
type AtomFunc ¶
type AtomFunc struct {
// contains filtered or unexported fields
}
AtomFunc is a function declaration.
func (*AtomFunc) FormatSpaces ¶
FormatSpaces removes useless space before, between and after the name and the body of the function declaration. If recomputeRaw is true, the raw value of the atom is recomputed.
func (*AtomFunc) GetBodyPositions ¶
func (AtomFunc) GetNamePositions ¶
func (*AtomFunc) RecomputeRaw ¶
func (a *AtomFunc) RecomputeRaw()
RecomputeRaw recomputes the raw value of the function declaration
func (*AtomFunc) SetBodyPositions ¶
func (AtomFunc) SetNamePositions ¶
type AtomGroup ¶
type AtomGroup struct { Childs Slice // contains filtered or unexported fields }
AtomGroup is a group of atoms It should contains: - one declaration atom (variable or function), - one comment.
func (*AtomGroup) FormatSpaces ¶
FormatSpaces removes useless spaces before, between and after each childs of the group. If recomputeRaw is true, it recomputes the raw string of the group.
func (AtomGroup) GetPositions ¶
func (*AtomGroup) RecomputRaw ¶
func (a *AtomGroup) RecomputRaw()
RecomputeRaw recompute the raw string of the group.
func (AtomGroup) SetPositions ¶
type AtomNamed ¶
type AtomNamed interface { Atom GetName() string GetNamePositions() (begin, end position.Position) SetName(string) SetNamePositions(begin, end position.Position) }
AtomNamed represents an atom of type declaration (function or variable).
type AtomValue ¶
type AtomValue struct {
// contains filtered or unexported fields
}
AtomValue is an atom containing a value of a variable declaration.
func (*AtomValue) GetDepends ¶
GetDepends returns the needed variable to fully compute the value.
func (*AtomValue) GetFormatted ¶
GetFormatted formats a value with or without quote depending of the given parameter.
func (*AtomValue) GetParsed ¶
GetParsed returns the real value, replacing the referenced variables by their values.
func (AtomValue) GetPositions ¶
func (*AtomValue) SetFormat ¶
func (a *AtomValue) SetFormat(f ValueFormatter)
SetFormat puts the format to use to compute and format the value.
func (AtomValue) SetPositions ¶
type AtomVar ¶
type AtomVar struct {
// contains filtered or unexported fields
}
AtomVar is a variable declaration.
func (*AtomVar) FormatSpaces ¶
FormatSpaces removes useless spaces of the atom. If recomputeRaw is true, the raw string is recomputed.
func (*AtomVar) FormatVariables ¶
FormatVariables reformats the values of the declaration, with or without quote depending to the value of the quoteNeeded parameter. If a type is given (should be of VarString or VarArray), the type of of the variable is forced.That means if an array variable becones a string variable, only the first value is kept. If recomputeRaw is true, the raw string of the declaration is recomputed.
func (*AtomVar) GetArrayFormatted ¶
GetArrayFormatted returns the list of the beautified values with or without quotes depending of the given parameter.
func (*AtomVar) GetArrayParsed ¶
GetArrayParsed returns the list of real values computed with the known values of the depending variables.
func (*AtomVar) GetArrayValue ¶
GetArrayValue returns the list of the raw string of the values.
func (*AtomVar) GetDepends ¶
GetDepends returns the list of the needed variables to compute the real values of the declaration.
func (AtomVar) GetNamePositions ¶
func (*AtomVar) GetStringFormatted ¶
GetStringFormatted is same as GetArrayFormatted but returns only the first entry or an empty string if no value).
func (*AtomVar) GetStringParsed ¶
GetStringParsed is same as GetArrayParsed but returns only the first entry or an empty string if no value).
func (*AtomVar) GetStringValue ¶
GetStringValue is same as GetArrayValue but returns only the first entry or an empty string if no value).
func (*AtomVar) GetValue ¶
GetValue returns the first value otom or false if the declaration is empty of values.
func (*AtomVar) RecomputRaw ¶
func (a *AtomVar) RecomputRaw()
RecomputeRaw recomputes the raw string of the atom.
func (*AtomVar) RemoveComments ¶
RemoveComments removes all inner comment of the declaration.
func (AtomVar) SetNamePositions ¶
type Info ¶
type Info struct { AtomNamed // contains filtered or unexported fields }
Info packs properties of a named atom.
func NewInfo ¶
NewInfo returns the infos of the given atom. If the atom is not a named atom or doesn’t contain a named atom, it returns false.
func (*Info) ArrayRawValue ¶
ArrayRawValue returns the raw values of the described atom or an empty array if it’s not a variable.
func (*Info) ArrayValue ¶
ArrayValue returns the values of the described atom or an empty array if it’s not a variable.
func (*Info) Body ¶
Body returns the raw content of the body function or an empty string if it’s not a function.
func (*Info) Function ¶
Function returns the functon atom described by the info, or false if it’s not a function atom.
func (*Info) IsArrayVar ¶
IsArrayVar returns true if the info concerns a variable of type array.
func (*Info) IsStringVar ¶
IsStringVar returns true if the info concerns a variable of type string.
func (*Info) StringRawValue ¶
StringRawValue returns the first raw value of the described atom or an empty string if it’s not a variable.
func (*Info) StringValue ¶
StringValue returns the first value of the described atom or an empty string if it’s not a variable.
type InfoList ¶
type InfoList struct {
// contains filtered or unexported fields
}
InfoList is a list of named infos in a slice of atoms.
func (*InfoList) Filter ¶
func (l *InfoList) Filter(cb NamedCheckerFunc) []*Info
Filter returns the infos of the atoms which pass le callback.
func (*InfoList) FilterFirst ¶
func (l *InfoList) FilterFirst(cb NamedCheckerFunc) (info *Info, exists bool)
FilterFirst returns the first atom which pass the callback or false if no atom was found.
func (*InfoList) GetByIndex ¶
GetByIndex returns the info on the given index.
func (*InfoList) GetDeep ¶
GetDeep returns the info of the atom wheter it is a named atom or a container, or false if not found.
func (*InfoList) GetNamed ¶
GetNamed returns the info of the given named atom or false if not found.
func (*InfoList) GetValue ¶
GetValue returns the value of the given variable name or an empty string if not found.
func (*InfoList) GetValues ¶
GetValues returns the list of the variable values indexed by the name of the variables.
func (*InfoList) HasValue ¶
HasValue returns true if the name is a variable name and if it has a value.
func (*InfoList) RecomputeValues ¶
func (l *InfoList) RecomputeValues()
RecomputeValues recomputes all values of all variable atoms.
func (*InfoList) Update ¶
Update updates the info of the given atom with the specified index and returns a rune code specific to the type of update: - 'A' if the info didn’t exist and was added, - 'D' if the info existed and was deleted, - 'U' if the info was found and some properties were modified, - 'O' if there was no change.
type NamedCheckerFunc ¶
func CheckName ¶
func CheckName(name string) NamedCheckerFunc
CheckName returns a callback to check if an atom declaration has the given name.
func NamedCheckAll ¶
func NamedCheckAll(checkers ...NamedCheckerFunc) NamedCheckerFunc
NamedCheckAll returns a callback checker which applies all given checkers.
func NewNameMatcher ¶
func NewNameMatcher(types ...AtomType) NamedCheckerFunc
NewNameMatcher returns a callback checking if an atom declaration has a supported type.
func NewRevNameMatcher ¶
func NewRevNameMatcher(types ...AtomType) NamedCheckerFunc
NewRevNameMatcher returns a callback checking if an atom declaration has not a supported type.
func RevNameCheck ¶
func RevNameCheck(cb NamedCheckerFunc) NamedCheckerFunc
RevNameCheck returns the inverse of the given callback.
type Slice ¶
type Slice []Atom
func (Slice) FilterFirst ¶
FilterFirst returns the firt atom matching one of the given types. It returns false if no atom was found.
func (Slice) FilterFirstRecursive ¶
FilterFirstRecursive is same as FilterFirst but it makes a deep search in searching in the atom containing other atoms.
func (Slice) FilterRecursive ¶
FilterRecursive is same as Filter but it makes a deep search in searching in the atom containing other atoms.
func (*Slice) Insert ¶
Insert appends the given atoms at the specified index of the slice. If the index is negative, it is counted from the end. For example, -1 is the last index of the slice.
func (Slice) Map ¶
Map apply a transfarmation function to each atom of the slice and returns the result of this transformation.
func (*Slice) Pop ¶
Pop removes the last element of the slice and returns it. If the slice is empty, it returns false.
func (*Slice) PopFront ¶
PopFront removes the first element of the slice and returns it. If the slice is empty, it returns false.
func (*Slice) Remove ¶
Pop removes the element at the given index of the slice and returns it. If the slice is empty or the index is not valid, it returns false.
func (Slice) Search ¶
func (l Slice) Search(cb AtomCheckerFunc, optRecursive ...bool) (result Slice)
Search returns all atoms matching the given checker. If recursive option is given and is true, it makes a deep search in searching in the atom containing other atoms.
func (Slice) SearchFirst ¶
func (l Slice) SearchFirst(cb AtomCheckerFunc, optRecursive ...bool) (result Atom, exists bool)
SearchFirst is same as Search but it returns only the first found atom. It returns false if no atom was found.
type TypeSet ¶
TypeSet is a set of atoms’ types.
func NewTypeSet ¶
func (TypeSet) MatchNamed ¶
MatchNamed checks if the given atom declaration has a type contained in the set.
type ValueElement ¶
type ValueElement struct {
// contains filtered or unexported fields
}
ValueElement represents an atomic part of a value It can be a string of the name of a referenced variable.
func (ValueElement) Format ¶
func (e ValueElement) Format(q rune) string
Format formats the element according to the given quote rune. It applies a transformation in escaping characters when needed.
func (ValueElement) Parse ¶
func (e ValueElement) Parse(depends map[string]string) string
Parse returns the computed string of the element using the given mapping (value of a known variable). If the element is a raw string, it returns it. Else it returns the value of the referenced variable (or an empty string if the variable doesn’t exist).
func (ValueElement) String ¶
func (e ValueElement) String() string
String returns the string representation of the part of the value. It can be on the form: - part if the element is a raw string - ${name} if the element is a reference to a variable.
type ValueFormatter ¶
type ValueFormatter []ValueElement
ValueFormatter represent parts of a value.
func NewValueFormatter ¶
func NewValueFormatter(s string) (f ValueFormatter, ok bool)
NewValueFormatter splits the given value in order to distinguish which part is a raw string and which part is a reference to a variable. It returns false if the parse failed.
func (ValueFormatter) Clone ¶
func (f ValueFormatter) Clone() ValueFormatter
Clone returns a copy of the formatter.
func (ValueFormatter) Debug ¶
func (f ValueFormatter) Debug() string
Debug returns a string representation of the formatter (for debugging only).
func (ValueFormatter) Format ¶
func (f ValueFormatter) Format(q rune) string
Format formats the value according to the given quote rune. It escapes chars when needed.
func (ValueFormatter) GetDepends ¶
func (f ValueFormatter) GetDepends() (depends []string)
GetDepends returns the list of the required variables’ names to fully compute the real value.
func (ValueFormatter) HasDep ¶
func (f ValueFormatter) HasDep() bool
HasDep returns true if the formmatter contains referenced variables.
func (ValueFormatter) Parse ¶
func (f ValueFormatter) Parse(depends map[string]string) string
Parse returns the computed value according to the value of the referenced variables.
func (ValueFormatter) String ¶
func (f ValueFormatter) String() string
String returns the string representation of the formatter.