Documentation
¶
Index ¶
- Variables
- func CloseAll()
- func OpenFile(path string) (*os.File, error)
- func ShouldStringBeQuoted(value string) bool
- type File
- type Hook
- type LiteralStringSegment
- type Locals
- type ModifierName
- type Node
- type NodeArgs
- type NodeCall
- type NodeChildren
- type NodeComment
- type NodeContext
- type NodeDirective
- type NodeExec
- type NodeLiteral
- type NodePipe
- type NodeRedirect
- type NodeRoot
- type NodeString
- type NodeWhitespace
- type Parser
- type SegmentedString
- type StringModifier
- type StringSegment
- type VariableStringSegment
Constants ¶
This section is empty.
Variables ¶
View Source
var AllModifiers = []ModifierName{ MOD_NOT, MOD_TO_LOWER, MOD_TO_UPPER, MOD_TO_SNAKE, MOD_TO_KEBAB, MOD_TO_CAMEL, MOD_TO_PASCAL, MOD_TO_DELIMITED, MOD_DOES_EXIST, MOD_IS_EMPTY, MOD_IS_FILE, MOD_IS_DIR, MOD_IS_SYMLINK, MOD_LENGTH, MOD_QUOTED, MOD_TRIM, MOD_TRIM_PREFIX, MOD_TRIM_SUFFIX, MOD_PAD, MOD_PAD_LEFT, MOD_PAD_RIGHT, MOD_HAS_PREFIX, MOD_HAS_SUFFIX, MOD_SLICE, MOD_REVERSE, MOD_INVERT, MOD_CONTAINS, }
View Source
var EOA = &liberrors.DetailedError{Name: "EOA", Details: "End of Arguments"}
View Source
var EOB = &liberrors.DetailedError{Name: "EOB", Details: "End of Block"}
View Source
var EOF = &liberrors.DetailedError{Name: "EOF", Details: "End of File"}
View Source
var OpenedFiles = []File{}
View Source
var UNEXPECTED_EOF = &liberrors.DetailedError{Name: "EOF", Details: "Unexpected End of File"}
Functions ¶
func CloseAll ¶
func CloseAll()
Close all OpenedFiles.
Recommended to be defered in [main], e.g. `defer libparser.CloseAll()`.
func OpenFile ¶
Recommended way of opening files for parsing.
Use `defer CloseAll()` in [main] to make sure no files are closed before parsing is finished.
func ShouldStringBeQuoted ¶
Types ¶
type Hook ¶
type Hook func(original Node) (modified Node, derr *liberrors.DetailedError)
A function to be called on every Node before the parser attempts to append it to the tree.
Return `nil` to discard the Node.
func StreamHook ¶
Puts the node to chan before it gets appended to the tree. Useful for tracking the progress of parsing in very large files.
Example usage: ¶
channel := make(chan libparser.Node)
parser := libparser.New(file)
parser.Hooks = []libparser.Hook{
libparser.StreamHook(channel),
}
go func() {
defer close(channel) // IMPORTANT! Without this you'll hang the process FOREVER.
if derr := parser.Run(); derr != nil {
...
}
}()
for node := range channel {
...
}
type LiteralStringSegment ¶
type LiteralStringSegment struct {
Contents string
}
func (*LiteralStringSegment) Eval ¶
func (segment *LiteralStringSegment) Eval(_ Locals) (string, error)
func (*LiteralStringSegment) Segment ¶
func (segment *LiteralStringSegment) Segment() string
type ModifierName ¶
type ModifierName string
const ( MOD_NOT ModifierName = "not" MOD_TO_LOWER ModifierName = "to_lower" MOD_TO_UPPER ModifierName = "to_upper" MOD_TO_SNAKE ModifierName = "to_snake" MOD_TO_KEBAB ModifierName = "to_kebab" MOD_TO_CAMEL ModifierName = "to_camel" MOD_TO_PASCAL ModifierName = "to_pascal" MOD_TO_DELIMITED ModifierName = "to_delimited" MOD_DOES_EXIST ModifierName = "does_exist" MOD_IS_EMPTY ModifierName = "is_empty" MOD_IS_FILE ModifierName = "is_file" MOD_IS_DIR ModifierName = "is_dir" MOD_IS_SYMLINK ModifierName = "is_symlink" MOD_LENGTH ModifierName = "length" MOD_QUOTED ModifierName = "quoted" MOD_TRIM ModifierName = "trim" MOD_TRIM_PREFIX ModifierName = "trim_prefix" MOD_TRIM_SUFFIX ModifierName = "trim_suffix" MOD_PAD ModifierName = "pad" MOD_PAD_LEFT ModifierName = "pad_left" MOD_PAD_RIGHT ModifierName = "pad_right" MOD_HAS_PREFIX ModifierName = "has_prefix" MOD_HAS_SUFFIX ModifierName = "has_suffix" MOD_SLICE ModifierName = "slice" MOD_REVERSE ModifierName = "reverse" MOD_INVERT ModifierName = "invert" MOD_CONTAINS ModifierName = "contains" )
type Node ¶
type Node interface {
Context() NodeContext
String() string
}
func ExcludeHook ¶
func ExcludeHook[T Node](node Node) (Node, *liberrors.DetailedError)
Discards Nodes of type T
func NoShebangHook ¶
func NoShebangHook(node Node) (Node, *liberrors.DetailedError)
Removes the UNIX shebang
type NodeCall ¶
type NodeCall struct {
Macro string
NodeContext
NodeArgs
}
func (*NodeCall) Context ¶
func (node *NodeCall) Context() NodeContext
type NodeChildren ¶
type NodeChildren []Node
func (NodeChildren) String ¶
func (children NodeChildren) String() string
type NodeComment ¶
type NodeComment struct {
Contents string
NodeContext
}
func (*NodeComment) Context ¶
func (node *NodeComment) Context() NodeContext
func (*NodeComment) String ¶
func (node *NodeComment) String() string
type NodeContext ¶
type NodeContext struct {
OffsetStart, OffsetEnd uint
}
func (NodeContext) String ¶
func (context NodeContext) String() string
type NodeDirective ¶
type NodeDirective struct {
Name string
NodeContext
NodeArgs
NodeChildren
}
func (*NodeDirective) Context ¶
func (node *NodeDirective) Context() NodeContext
func (*NodeDirective) String ¶
func (node *NodeDirective) String() string
type NodeExec ¶
type NodeExec struct {
Name string
NodeContext
NodeArgs
}
func (*NodeExec) Context ¶
func (node *NodeExec) Context() NodeContext
type NodeLiteral ¶
type NodeLiteral struct {
Contents string
NodeContext
}
func (*NodeLiteral) Context ¶
func (node *NodeLiteral) Context() NodeContext
func (*NodeLiteral) String ¶
func (node *NodeLiteral) String() string
func (*NodeLiteral) ToStringNode ¶
func (node *NodeLiteral) ToStringNode() *NodeString
type NodePipe ¶
type NodePipe struct {
Source Node
Dest Node
NodeContext
}
func (*NodePipe) Context ¶
func (node *NodePipe) Context() NodeContext
type NodeRedirect ¶
type NodeRedirect struct {
Source Node
Stdin *NodeString
Stdout *NodeString
Stderr *NodeString
NodeContext
}
func (*NodeRedirect) Context ¶
func (node *NodeRedirect) Context() NodeContext
func (*NodeRedirect) String ¶
func (node *NodeRedirect) String() string
type NodeRoot ¶
type NodeRoot struct {
Tomes map[string]*NodeDirective
NodeContext
NodeChildren
}
func (*NodeRoot) Context ¶
func (node *NodeRoot) Context() NodeContext
type NodeString ¶
type NodeString struct {
Segments SegmentedString
NodeContext
}
func NewSimpleNodeString ¶
func NewSimpleNodeString(contents string) *NodeString
func (*NodeString) Context ¶
func (node *NodeString) Context() NodeContext
func (*NodeString) String ¶
func (node *NodeString) String() string
type NodeWhitespace ¶
type NodeWhitespace struct {
IsLineBreak bool
NodeContext
}
func (*NodeWhitespace) Context ¶
func (node *NodeWhitespace) Context() NodeContext
func (*NodeWhitespace) String ¶
func (node *NodeWhitespace) String() string
type Parser ¶
type Parser struct {
Parent *Parser
File File
Result *NodeRoot
Hooks []Hook
// contains filtered or unexported fields
}
func (*Parser) Run ¶
func (parser *Parser) Run() *liberrors.DetailedError
type SegmentedString ¶
type SegmentedString []StringSegment
func (SegmentedString) String ¶
func (segments SegmentedString) String() string
type StringModifier ¶
type StringModifier struct {
Name ModifierName
Args []*NodeString
Call func(Locals, string) string
}
func GetModifier ¶
func GetModifier(name ModifierName, args []*NodeString) (StringModifier, error)
func SortNotModifierToEnd ¶
func SortNotModifierToEnd(modifiers []StringModifier) []StringModifier
func (StringModifier) MarshalJSON ¶
func (modifier StringModifier) MarshalJSON() ([]byte, error)
func (StringModifier) String ¶
func (modifier StringModifier) String() string
type VariableStringSegment ¶
type VariableStringSegment struct {
Name string
Modifiers []StringModifier
IsOptional bool
}
func (*VariableStringSegment) Eval ¶
func (segment *VariableStringSegment) Eval(locals Locals) (string, error)
func (*VariableStringSegment) Segment ¶
func (segment *VariableStringSegment) Segment() string
Source Files
¶
Click to show internal directories.
Click to hide internal directories.