ast

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Assignment

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

func (*Assignment) BelongsToGroup

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

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) HasComments

func (a *Assignment) HasComments() bool

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) IsValid added in v0.5.0

func (a *Assignment) IsValid() error

func (*Assignment) Type added in v0.3.0

func (a *Assignment) Type() string

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 (*Comment) BelongsToGroup

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

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
}

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

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) GetConfig

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

func (*Document) GetGroup

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

func (*Document) GetPosition

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

func (*Document) Interpolate added in v0.4.0

func (doc *Document) Interpolate(target *Assignment) (string, error)

func (*Document) Is

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

func (*Document) Type added in v0.3.0

func (d *Document) Type() string

func (*Document) Upsert added in v0.4.0

func (doc *Document) Upsert(input *Assignment, options UpsertOptions) (*Assignment, 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) BelongsToGroup

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

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 {
	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 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 SelectorResult added in v0.6.2

type SelectorResult uint
const (
	Exclude SelectorResult = iota
	Keep
)

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

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 UpsertOptions added in v0.4.0

type UpsertOptions struct {
	InsertBefore   string
	Comments       []string
	ErrorIfMissing bool
	Group          string
	SkipIfSame     bool
	SkipIfSet      bool
	SkipValidation bool
}

Jump to

Keyboard shortcuts

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