naive

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package naive provides a deliberately minimal PHP parser and pretty-printer.

The parser recognises only two node types---blocks (scopes) and generic statements (or list items)---so it does not model PHP’s full grammar. The printer can re-emit any valid PHP file (and often even invalid ones), but it normalises the output: spacing, line breaks, and other cosmetic trivia may differ from the original source, although the program’s behaviour is preserved.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fprint

func Fprint(w io.Writer, node any, options Options) error

Fprint pretty-prints an AST node to w.

Types

type File

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

func Parse

func Parse(r io.Reader, php74Compat bool) (*File, error)

Parse parses a single PHP file. If an error occurs while parsing (except io errors), the returned error will be of type *SyntaxError.

type Options

type Options uint8
const (
	// TrailingComma enables adding trailing commas in all [] and () scopes.
	TrailingComma Options = 1 << iota

	// AlignColumns causes Fprint to align elements in columns using spaces.
	AlignColumns

	// PHP74Compat switches formatting to PHP 7.4 compatibility mode.
	//
	// - This will remove support for trailing comma.
	// - The concat operator (.) is formatted according to PHP 7.4 precedence rules.
	PHP74Compat

	// Standard is the default, “standard” formatting style.
	Standard = TrailingComma | AlignColumns
)

type SyntaxError

type SyntaxError struct {
	Line, Column int
	Err          error
}

SyntaxError records an error and the position it occurred on.

func (*SyntaxError) Error

func (e *SyntaxError) Error() string

Jump to

Keyboard shortcuts

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