parser

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package parser provides command file parsing functionality.

Package parser provides command file parsing functionality.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyFile            = errors.New("file is empty")
	ErrMalformedFrontmatter = errors.New("malformed frontmatter")
)

Sentinel errors for command parsing.

Functions

This section is empty.

Types

type Commandable

type Commandable interface {
	GetName() string
	SetName(string)
	SetInstructions(string)
}

Commandable is implemented by command types that can have their Name and Instructions set.

type ParseError

type ParseError struct {
	Path string
	Err  error
}

ParseError represents an error that occurred while parsing a command file.

func (*ParseError) Error

func (e *ParseError) Error() string

func (*ParseError) Unwrap

func (e *ParseError) Unwrap() error

type Parser

type Parser[T Commandable] struct{}

Parser handles command file parsing operations.

func New

func New[T Commandable]() *Parser[T]

New creates a new Parser instance.

func (*Parser[T]) Parse

func (p *Parser[T]) Parse(r io.Reader, path string) (*T, error)

Parse reads and parses a command from the given reader. The path parameter is used for error context and name inference.

func (*Parser[T]) ParseBytes

func (p *Parser[T]) ParseBytes(data []byte, path string) (*T, error)

ParseBytes parses command content from bytes. The path parameter is used for error context and name inference.

func (*Parser[T]) ParseFile

func (p *Parser[T]) ParseFile(path string) (*T, error)

ParseFile reads and parses a command file from the given path. Returns the parsed command or an error if parsing fails.

func (*Parser[T]) ParseHeader

func (p *Parser[T]) ParseHeader(path string) (*T, error)

ParseHeader parses only the frontmatter metadata, stopping at the closing ---. This is more efficient for listing commands without reading full content.

Jump to

Keyboard shortcuts

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