formatter

package
v1.34.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package formatter provides source code formatting for ELPS lisp files. It uses the ELPS parser in format-preserving mode to parse source code into an annotated AST, then walks the tree to produce formatted output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultRules

func DefaultRules() map[string]*IndentRule

DefaultRules returns the default indent rules table.

func Format

func Format(source []byte, cfg *Config) ([]byte, error)

Format formats ELPS source code. If cfg is nil, DefaultConfig() is used.

func FormatFile

func FormatFile(source []byte, filename string, cfg *Config) ([]byte, error)

FormatFile formats ELPS source code, using filename for error messages.

Types

type Config

type Config struct {
	IndentSize    int                    // spaces per indent level (default: 2)
	MaxBlankLines int                    // max consecutive blank lines (default: 1)
	Rules         map[string]*IndentRule // form name -> rule
}

Config holds formatting configuration.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default formatting configuration.

func (*Config) RuleFor

func (c *Config) RuleFor(name string) *IndentRule

RuleFor returns the indent rule for the given form name. If no specific rule exists, returns the default first-arg alignment rule. Forms starting with "def" get defun-style indent (2 header args + body), following the common Lisp convention for definition forms.

type IndentRule

type IndentRule struct {
	Style      IndentStyle
	HeaderArgs int // for IndentSpecial: args before the "body"
}

IndentRule specifies the indentation behavior for a particular form.

type IndentStyle

type IndentStyle int

IndentStyle determines how arguments in an s-expression are indented.

const (
	// IndentAlign indents subsequent lines to align with the first argument.
	IndentAlign IndentStyle = iota
	// IndentBody indents all subforms at bracket column + indent size.
	IndentBody
	// IndentSpecial indents N header args aligned, rest at bracket + indent size.
	IndentSpecial
)

Jump to

Keyboard shortcuts

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