parser

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = &Config{
	Logger:         slog.Default(),
	IgnoreSections: false,
}

Functions

func DetectLineType

func DetectLineType(line string) common.LineType

func FindTerminator

func FindTerminator(line string, pos int, terminator byte) int

findTerminator finds the closing quote, accounting for escaping.

func GetQuoteFromValType

func GetQuoteFromValType(t ValueType) (isQuoted bool, quote byte)

func IsLineComment

func IsLineComment(line string) bool

IsLineComment checks if a line is a comment (starts with # after optional spaces).

Types

type Config

type Config struct {
	Logger         *slog.Logger
	IgnoreSections bool
}

type FileParser

type FileParser struct {
	common.Parser

	CurrentIdx int64
	// contains filtered or unexported fields
}

func NewFileParser

func NewFileParser(p common.Parser, reader *bufio.Reader, keepNewLine bool, options ...Option) *FileParser

func (*FileParser) GetLineIdx

func (p *FileParser) GetLineIdx() int64

func (*FileParser) Next

func (p *FileParser) Next() (common.ParsedLine, error)

type KeyData

type KeyData struct {
	Key   string
	Start int
	End   int
}

KeyData holds information about an extracted key.

func ExtractKey

func ExtractKey(line string, equalIdx int) (KeyData, error)

ExtractKey extracts the key from line given the position of '=' Returns the key string or error if invalid.

type Option

type Option func(*Config)

func SetIgnoreSections

func SetIgnoreSections(ignore bool) Option

func SetLogger

func SetLogger(l *slog.Logger) Option

type Parser

type Parser struct {
	*Config
	// contains filtered or unexported fields
}

func New

func New(options ...Option) *Parser

func (*Parser) ParseLine

func (p *Parser) ParseLine(line string) (common.ParsedLine, error)

ParseLine takes as an input line from an environment file and outputs parsed line Lines from the file must be passed sequentially.

type ValueData

type ValueData struct {
	Raw          string    // The raw value including quotes if present
	Content      string    // The actual content (without quotes)
	Start        int       // Start position in the line
	End          int       // End position in the line
	Type         ValueType // Whether the value was quoted and with what
	IsTerminated bool      // Whether quotes were properly closed
}

ValueData holds information about an extracted value.

func ExtractValue

func ExtractValue(line string, equalIdx int) (ValueData, error)

ExtractValue extracts the value from line given the position of '=' Returns structured value data and any error.

type ValueType

type ValueType int
const (
	ValueUnquoted ValueType = iota
	ValueSingleQuoted
	ValueDoubleQuoted
)

type VariableData

type VariableData struct {
	Key   KeyData
	Value ValueData
}

VariableData holds information about a parsed variable.

func ParseVariable

func ParseVariable(line string) (VariableData, error)

ParseVariable parses a line for a variable assignment (KEY=VALUE) Returns variable data and error.

Jump to

Keyboard shortcuts

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