ast

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2024 License: MIT Imports: 9 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) Assignment

func (a *Assignment) Assignment(config RenderSettings) string

func (*Assignment) BelongsToGroup

func (a *Assignment) BelongsToGroup(config RenderSettings) bool

func (*Assignment) HasComments

func (a *Assignment) HasComments() bool

func (*Assignment) Is

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

func (*Assignment) Render

func (a *Assignment) Render(config RenderSettings) string

func (*Assignment) RenderDocumentation

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

func (*Assignment) SetQuote

func (a *Assignment) SetQuote(in 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(config RenderSettings) bool

func (*Comment) Is

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

func (*Comment) Render

func (c *Comment) Render(config RenderSettings) string

func (*Comment) String

func (c *Comment) String() 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(config RenderSettings) bool

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(config RenderSettings) *Group

func (*Document) GetInterpolation

func (d *Document) GetInterpolation(in string) (string, bool)

func (*Document) GetPosition

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

func (*Document) Is

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

func (*Document) Render

func (d *Document) Render(config RenderSettings) string

func (*Document) RenderFull

func (d *Document) RenderFull() string

func (*Document) Set

func (doc *Document) Set(input *Assignment, options SetOptions) (bool, error)

type Group

type Group struct {
	Name       string      // Name of the group (within the header)
	Statements []Statement // Statements within the group
	Position   Position    // Positional information about the group
}

func (*Group) BelongsToGroup

func (g *Group) BelongsToGroup(config RenderSettings) bool

func (*Group) Is

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

func (*Group) Render

func (g *Group) Render(config RenderSettings) string

func (*Group) String

func (g *Group) String() string

type Newline

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

func (*Newline) BelongsToGroup

func (n *Newline) BelongsToGroup(config RenderSettings) bool

func (*Newline) Is

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

func (*Newline) Render

func (n *Newline) Render(config RenderSettings) string

type Position

type Position struct {
	File      string
	Line      uint
	FirstLine uint
	LastLine  uint
}

func (Position) String

func (p Position) String() string

type RenderSettings

type RenderSettings struct {
	FilterKeyPrefix  string
	FilterGroup      string
	IncludeCommented bool

	ShowPretty     bool
	ShowComments   bool
	ShowGroups     bool
	ShowBlankLines bool
	ShowColors     bool

	Interpolate bool
}

func (*RenderSettings) Match

func (rs *RenderSettings) Match(assignment *Assignment) bool

func (*RenderSettings) WithBlankLines

func (rs *RenderSettings) WithBlankLines() bool

func (*RenderSettings) WithColors

func (rs *RenderSettings) WithColors() bool

func (*RenderSettings) WithComments

func (rs *RenderSettings) WithComments() bool

func (*RenderSettings) WithGroups

func (rs *RenderSettings) WithGroups() bool

type SetOptions

type SetOptions struct {
	ErrorIfMissing bool
	SkipIfSet      bool
	SkipIfSame     bool
	Group          string
	Before         string
	Comments       []string
}

type Statement

type Statement interface {
	Is(Statement) bool
	BelongsToGroup(RenderSettings) bool
	Render(RenderSettings) string
	// contains filtered or unexported methods
}

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

Jump to

Keyboard shortcuts

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