ast

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2022 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Write

func Write(f File, output string) error

Write writes an AST file to a file on disk.

Types

type Comment

type Comment struct {
	Str string
}

Comment is any whitespace or comment that is ignored by this parser

type Field

type Field struct {
	Str             string // The literal value of this line, including comments and whitespace e.g. Foo = Bar ; test
	Name            string
	Value           string
	TrailingComment string     // Any comments or whitespace after the field value
	CommentsBefore  []*Comment // Any comments or whitespace between this field and whatever came before
}

type File

type File struct {
	Sections      []*Section
	CommentsAfter []*Comment // Any comments or whitespace that come at the end of a file
	Fields        []*Field   // Fields that don't belong to a section
}

File is an AST representation of a config file

func AppendBlankLineToFile

func AppendBlankLineToFile(f File) File

AppendBlankLine appends an empty line to the file.

func AppendBlankLineToSection

func AppendBlankLineToSection(f File, sectionName, subsectionName string) (File, bool)

AppendBlankLineToSection appends an empty to a section

func AppendFieldToSection

func AppendFieldToSection(f File, fieldName, fieldValue, sectionName, subsectionName string) File

AppendFieldToSection appends a field to a section with no knowledge of whether the field is repeatable or not. Creates a new section if section does not exist

func DeleteAllFieldsWithName

func DeleteAllFieldsWithName(f File, fieldName, sectionName, subsectionName string) File

DeleteAllFieldsWithName deletes all fields with the name fieldName in section [sectionName "subsectionName"]

func DeleteFieldWithValue

func DeleteFieldWithValue(f File, fieldName, fieldValue, sectionName, subsectionName string) File

DeleteFieldWithValue deletes a field from a section if the name and value are fieldName and fieldValue

func DeleteSection

func DeleteSection(file File, sect, subsection string) File

DeleteSection deletes all sections found in the AST with the name sect

func InjectField

func InjectField(f File, fieldName, fieldValue, sectionName, subsectionName string, repeatable bool) File

InjectField injects a field into the AST and returns the modified file. If multiple sections exist with the same name, the field is inserted into the first one found.

func MakeNewSection

func MakeNewSection(f File, sectionName, subsectionName string) (File, bool)

MakeNewSection writes a new section heading to the file. Returns !ok if section already exists.

func MergeAllDuplicateSections

func MergeAllDuplicateSections(file File) File

MergeAllDuplicateSections merges all sections with duplicate names, along with any fields and comments belonging to them

func Read

func Read(file io.Reader) File

func (File) MaybeGetSection

func (f File) MaybeGetSection(sectionName, subsectionName string) *Section

MaybeGetSection returns a pointer to a section with name sectionName and subsection subsectionName. Returns nil if section does not exist.

type Section

type Section struct {
	HeadingStr     string // The literal value of this section heading
	Name           string
	Subsection     string
	Key            string // Section identifier
	Fields         []*Field
	CommentsBefore []*Comment // Any comments or whitespace between this field and whatever came before
}

Jump to

Keyboard shortcuts

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