ast

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package ast declares the types used to represent syntax trees for the .env file.

Index

Constants

View Source
const (
	Exclude selectorResult = iota
	Keep
)

Variables

This section is empty.

Functions

func ContextualError added in v0.8.0

func ContextualError(stmt Statement, err error) error

func ExcludeActiveAssignments added in v0.6.2

func ExcludeActiveAssignments(input Statement) selectorResult

ExcludeActiveAssignments will exclude *ACTIVE* Assignments

func ExcludeComments added in v0.6.2

func ExcludeComments(input Statement) selectorResult

ExcludeComments will *EXCLUDE* all comments

func ExcludeDisabledAssignments added in v0.6.2

func ExcludeDisabledAssignments(input Statement) selectorResult

ExcludeDisabledAssignments will exclude *DISABLED* Assignments

func ExcludeHiddenViaAnnotation added in v0.6.2

func ExcludeHiddenViaAnnotation(input Statement) selectorResult

ExcludeHiddenViaAnnotation will exclude *HIDDEN* Assignments via the [@dottie/hidden] annotation

Types

type Assignment

type Assignment struct {
	Complete     bool                         `json:"complete"`     // The key/value had no value/content after the "=" sign
	Enabled      bool                         `json:"enabled"`      // The assignment was enabled out (#KEY=VALUE)
	Interpolated string                       `json:"interpolated"` // Value of the key (after interpolation)
	Literal      string                       `json:"literal"`      // Value of the key (right hand side of the "=" sign)
	Name         string                       `json:"key"`          // Name of the key (left hand side of the "=" sign)
	Quote        token.Quote                  `json:"quote"`        // The style of quotes used for the assignment
	Position     Position                     `json:"position"`     // Information about position of the assignment in the file
	Comments     []*Comment                   `json:"comments"`     // Comments attached to the assignment (e.g. doc block before it)
	Dependencies map[string]template.Variable `json:"dependencies"` // Assignments that this assignment depends on
	Dependents   map[string]*Assignment       `json:"dependents"`   // Assignments dependents on this assignment
	Group        *Group                       `json:"-"`            // The (optional) group this assignment belongs to
}

func (*Assignment) Annotation added in v0.10.0

func (a *Assignment) Annotation(name string) []string

func (*Assignment) BelongsToGroup

func (a *Assignment) BelongsToGroup(name string) bool

func (*Assignment) CommentsSlice added in v0.7.0

func (a *Assignment) CommentsSlice() []string

func (*Assignment) Disable added in v0.6.0

func (a *Assignment) Disable()

func (*Assignment) Documentation added in v0.2.0

func (a *Assignment) Documentation(withoutPrefix bool) string

func (*Assignment) DocumentationSummary added in v0.6.2

func (a *Assignment) DocumentationSummary() string

func (*Assignment) Enable added in v0.6.0

func (a *Assignment) Enable()

func (*Assignment) GetSafeLiteral added in v0.11.0

func (a *Assignment) GetSafeLiteral() string

func (*Assignment) HasComments

func (a *Assignment) HasComments() bool

func (*Assignment) Initialize added in v0.8.0

func (a *Assignment) Initialize(ctx context.Context)

func (*Assignment) Is

func (a *Assignment) Is(other Statement) bool

func (*Assignment) IsHidden added in v0.6.2

func (a *Assignment) IsHidden() bool

func (*Assignment) SetLiteral added in v0.9.4

func (a *Assignment) SetLiteral(ctx context.Context, in string)

func (*Assignment) Type added in v0.3.0

func (a *Assignment) Type() string

func (*Assignment) Unquote added in v0.9.4

func (a *Assignment) Unquote(ctx context.Context) (string, error)

func (*Assignment) ValidationRules

func (a *Assignment) ValidationRules() string

type Comment

type Comment struct {
	Value      string            `json:"value"`      // The actual comment value
	Annotation *token.Annotation `json:"annotation"` // If the comment was detected to be an annotation
	Group      *Group            `json:"-"`          // The (optional) group the comment belongs to
	Position   Position          `json:"position"`   // Information about position of the assignment in the file
}

Comment node represents a comment statement.

func NewComment

func NewComment(value string) *Comment

func NewCommentsFromSlice added in v0.8.0

func NewCommentsFromSlice(commentsSlice []string) []*Comment

func (*Comment) BelongsToGroup

func (c *Comment) BelongsToGroup(name string) bool

func (Comment) CleanString added in v0.7.0

func (c Comment) CleanString() string

func (*Comment) Is

func (c *Comment) Is(other Statement) bool

func (Comment) String

func (c Comment) String() string

func (*Comment) Type added in v0.3.0

func (c *Comment) Type() string

type Document

type Document struct {
	Statements  []Statement `json:"statements"` // Statements belonging to the root of the document
	Groups      []*Group    `json:"groups"`     // Groups within the document
	Annotations []*Comment  `json:"-"`          // Global annotations for configuration of dottie
	// contains filtered or unexported fields
}

Document node represents .env file statement, that contains assignments and comments.

func NewDocument added in v0.8.0

func NewDocument() *Document

func (*Document) AccessibleVariables added in v0.10.0

func (doc *Document) AccessibleVariables(target *Assignment) func() map[string]string

func (*Document) AllAssignments added in v0.7.0

func (d *Document) AllAssignments(selectors ...Selector) []*Assignment

func (*Document) Assignments

func (d *Document) Assignments() []*Assignment

func (*Document) BelongsToGroup

func (d *Document) BelongsToGroup(name string) bool

func (*Document) EnsureGroup added in v0.1.0

func (doc *Document) EnsureGroup(name string) *Group

func (*Document) Get

func (d *Document) Get(name string) *Assignment

func (*Document) GetAssignmentIndex added in v0.7.0

func (d *Document) GetAssignmentIndex(name string) (int, *Assignment)

func (*Document) GetConfig

func (d *Document) GetConfig(name string) (string, error)

func (*Document) GetGroup

func (d *Document) GetGroup(name string) *Group

func (*Document) Has added in v0.7.0

func (d *Document) Has(name string) bool

func (*Document) HasGroup added in v0.7.0

func (d *Document) HasGroup(name string) bool

func (*Document) Initialize added in v0.8.0

func (document *Document) Initialize(ctx context.Context)

func (*Document) InterpolateAll added in v0.8.0

func (doc *Document) InterpolateAll(ctx context.Context) error

func (*Document) InterpolateStatement added in v0.8.0

func (doc *Document) InterpolateStatement(ctx context.Context, target *Assignment) error

func (*Document) InterpolationMapper added in v0.10.0

func (doc *Document) InterpolationMapper(target *Assignment) func(input string) (string, bool)

func (*Document) Is

func (d *Document) Is(other Statement) bool

func (*Document) ReindexStatements added in v0.8.0

func (d *Document) ReindexStatements()

func (*Document) Replace added in v0.8.0

func (document *Document) Replace(assignment *Assignment) error

func (*Document) Type added in v0.3.0

func (d *Document) Type() string

func (*Document) Validate added in v0.9.0

func (document *Document) Validate(ctx context.Context, selectors []Selector, ignoreErrors []string) ([]*ValidationError, error)

func (*Document) ValidateSingleAssignment added in v0.9.0

func (document *Document) ValidateSingleAssignment(ctx context.Context, assignment *Assignment, selectors []Selector, ignoreErrors []string) (ValidationErrors, error)

type Group

type Group struct {
	Name       string      `json:"name"`       // Name of the group (within the header)
	Statements []Statement `json:"statements"` // Statements within the group
	Position   Position    `json:"position"`   // Positional information about the group
}

func (*Group) Assignments added in v0.7.0

func (g *Group) Assignments() []*Assignment

func (*Group) BelongsToGroup

func (g *Group) BelongsToGroup(name string) bool

func (*Group) GetAssignmentIndex added in v0.7.0

func (g *Group) GetAssignmentIndex(name string) (int, *Assignment)

func (*Group) Is

func (g *Group) Is(other Statement) bool

func (*Group) String

func (g *Group) String() string

func (*Group) Type added in v0.3.0

func (g *Group) Type() string

type Newline

type Newline struct {
	Blank    bool     `json:"blank"`
	Group    *Group   `json:"-"`
	Repeated int      `json:"repeated"`
	Position Position `json:"position"`
}

func (*Newline) Is

func (n *Newline) Is(other Statement) bool

func (*Newline) Type added in v0.3.0

func (n *Newline) Type() string

type Position

type Position struct {
	Index     int    `json:"index"`
	File      string `json:"file"`
	Line      uint   `json:"line"`
	FirstLine uint   `json:"first_line"`
	LastLine  uint   `json:"last_line"`
}

func (Position) String

func (p Position) String() string

type Selector added in v0.6.2

type Selector func(input Statement) selectorResult

func ExcludeKeyPrefix added in v0.6.2

func ExcludeKeyPrefix(prefix string) Selector

ExcludeKeyPrefix will *EXCLUDE* Assignments with the provided prefix

func RetainExactKey added in v0.6.9

func RetainExactKey(key ...string) Selector

RetainExactKey will *RETAIN* Assignments with the exact name

func RetainGroup added in v0.6.2

func RetainGroup(name string) Selector

RetainGroup will exclude Assignment, Group, and Comment statements that do not belong to the provided group name

func RetainKeyPrefix added in v0.6.2

func RetainKeyPrefix(prefix string) Selector

RetainKeyPrefix will *RETAIN* Assignments with the provided prefix

type Statement

type Statement interface {
	Is(statement Statement) bool
	Type() string
	// contains filtered or unexported methods
}

Statement represents syntax tree node of .env file statement (like: assignment or comment).

type StatementCollection added in v0.7.0

type StatementCollection interface {
	Assignments() []*Assignment
	GetAssignmentIndex(name string) (int, *Assignment)
}

type ValidationError added in v0.9.0

type ValidationError struct {
	WrappedError any
	Assignment   *Assignment
}

func NewError added in v0.9.0

func NewError(assignment *Assignment, err error) *ValidationError

func (ValidationError) Error added in v0.9.0

func (e ValidationError) Error() string

type ValidationErrors added in v0.9.0

type ValidationErrors []*ValidationError

func (ValidationErrors) Error added in v0.9.0

func (x ValidationErrors) Error() string

func (ValidationErrors) Errors added in v0.9.0

func (x ValidationErrors) Errors() []*ValidationError

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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