parser

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(src string) (*File, []*ParseError)

Parse tokenizes src and builds an AST. It returns a (possibly partial) File along with any parse errors encountered.

Types

type Argument

type Argument struct {
	Token Token
}

Argument is a single token value used as an argument to a directive.

func (*Argument) Range

func (a *Argument) Range() protocol.Range

type Directive

type Directive struct {
	Name      Token
	Args      []*Argument
	Body      []*Directive // sub-directives inside { }
	StartLine uint32
	EndLine   uint32
}

Directive is a named directive with optional arguments and a body block.

func (*Directive) Range

func (d *Directive) Range() protocol.Range

type File

type File struct {
	GlobalBlock *GlobalBlock // optional; nil if absent
	SiteBlocks  []*SiteBlock
}

File is the root AST node for a Caddyfile.

func (*File) Range

func (f *File) Range() protocol.Range

type GlobalBlock

type GlobalBlock struct {
	Directives []*Directive
	StartLine  uint32
	EndLine    uint32
}

GlobalBlock represents the global options block `{ ... }` at the top of a Caddyfile.

func (*GlobalBlock) Range

func (g *GlobalBlock) Range() protocol.Range

type Node

type Node interface {
	Range() protocol.Range
}

Node is the interface implemented by every AST node.

type ParseError

type ParseError struct {
	Message string
	Rng     protocol.Range
}

ParseError holds a diagnostic-friendly parse error.

func (*ParseError) Error

func (e *ParseError) Error() string

type SiteBlock

type SiteBlock struct {
	Addresses  []Token
	Directives []*Directive
	StartLine  uint32
	EndLine    uint32
}

SiteBlock represents a site address block, e.g. `example.com { ... }`.

func (*SiteBlock) Range

func (s *SiteBlock) Range() protocol.Range

type Token

type Token struct {
	Type  TokenType
	Value string
	Line  uint32 // 0-based
	Char  uint32 // 0-based character offset on the line
}

Token is the smallest unit produced by the lexer.

func Tokenize

func Tokenize(src string) []Token

Tokenize uses Caddy's official Caddyfile tokenizer and enriches each token with column information derived by scanning the source text.

Note: COMMENT and NEWLINE tokens are not produced because Caddy's tokenizer strips comments and does not emit newlines as separate tokens. The NEWLINE and COMMENT enum values are retained for backward compatibility only.

func (Token) Range

func (t Token) Range() protocol.Range

type TokenType

type TokenType int

TokenType enumerates all token kinds.

const (
	ILLEGAL TokenType = iota
	EOF
	IDENT   // any unquoted word / address / directive name
	LBRACE  // {
	RBRACE  // }
	NEWLINE // retained for enum compatibility; not produced by Caddy's tokenizer
	COMMENT // retained for enum compatibility; not produced by Caddy's tokenizer
	STRING  // "…" or `…`
)

func (TokenType) String

func (t TokenType) String() string

Jump to

Keyboard shortcuts

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