lexer

package
v2.0.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	QuoteTypeNone = iota
	QuoteTypeSingle
	QuoteTypeDouble
)

Variables

This section is empty.

Functions

func IsGenericError

func IsGenericError(err error) (error, bool)

IsGenericError checks if the error is a GenericError.

Types

type GenericError

type GenericError struct {
	Err    error `json:"error"`
	Line   int   `json:"line"`
	Column int   `json:"column"`
}

GenericError is a generic error that can be returned by the lexer.

func (*GenericError) Error

func (e *GenericError) Error() string

func (*GenericError) Unwrap

func (e *GenericError) Unwrap() error

type QuoteType

type QuoteType int

type Reference

type Reference struct {
	Token     Token     // Token that represents the literal.
	Position  int       // Character position of the token in the input.
	Line      int       // Line number of the token in the input.
	Column    int       // Column number of the token in the input.
	Value     string    // Literal value of the token.
	QuoteType QuoteType // Type of quote used, if any.
}

Reference represents a reference to a token in the input, and the associated context.

type StatefulLexer

type StatefulLexer struct {
	// contains filtered or unexported fields
}

StatefulLexer is a lexer that maintains state between calls to [Iter], and only applies specific idents when applicable. We keep this state/context validation mostly because dot env files are pretty loose, and can be written in a variety of ways with very little strictness.

func New

func New(input string) *StatefulLexer

New creates a new StatefulLexer. Note that all windows-style carriage returns are converted to newlines.

func (*StatefulLexer) Iter

func (l *StatefulLexer) Iter() iter.Seq2[*Reference, error]

Iter iterates over the lexer's input and yields references to the tokens found.

type Token

type Token string

Token represents a token ("identifier") in the input.

const (
	EOF        Token = "EOF"
	Whitespace Token = "WHITESPACE"
	Newline    Token = "NEWLINE"
	Comment    Token = "COMMENT"
	Export     Token = "EXPORT"
	Key        Token = "KEY"
	Equals     Token = "EQUALS"
	Value      Token = "VALUE"
)

func (Token) String

func (t Token) String() string

Jump to

Keyboard shortcuts

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