augment

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package augment facilitates adding syntax to the Go AST.

It works by replacing invalid syntax with valid code, recording these positions as it does so, allowing us to later transform the parsed AST for affected nodes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Augment

func Augment(src []byte) ([]byte, []Augmentation, []PosAdjustment, error)

Augment takes the provided pgo syntax and returns valid Go syntax, a list of augmentations made to it, and position adjustments required in the parsed AST.

Types

type Augmentation

type Augmentation interface {

	// Start returns the offset at which the augmentation was found.
	Start() int

	// End returns the offset of the first character immediately after this
	// augmentation.
	//
	// Given an augmentation a in text, text[a.Start():a.End()] fully
	// encapsulates the text of the augmentation.
	End() int
	// contains filtered or unexported methods
}

Augmentation is an addition to the Go syntax for pgo.

type Dots

type Dots struct {
	DotsStart, DotsEnd int

	// Named indicates whether the dots replace a named entity — such
	// as the named arguments or results of a function.
	Named bool
}

Dots is a "..." operator appearing in the Go source outside of places allowed by the Go syntax.

func (*Dots) End

func (d *Dots) End() int

End offset of Dots.

func (*Dots) Start

func (d *Dots) Start() int

Start offset of Dots.

type FakeFunc

type FakeFunc struct {
	FuncStart int  // position of "func" keyword
	Braces    bool // whether a { ... } was added
}

FakeFunc is a fake function block generated in the code. This is needed if the source didn't open with a valid top-level declaration.

func (*FakeFunc) End

func (f *FakeFunc) End() int

End offset for FakeFunc. This is meaningless for FakeFunc.

func (*FakeFunc) Start

func (f *FakeFunc) Start() int

Start offset for FakeFunc.

type FakePackage

type FakePackage struct {
	PackageStart int // position of "package" keyword
}

FakePackage is a fake package clause included in the code. This is needed if the source didn't contain a package clause.

func (*FakePackage) End

func (p *FakePackage) End() int

End offset for FakePackage. This is meaningless for FakePackage.

func (*FakePackage) Start

func (p *FakePackage) Start() int

Start offset for FakePackage.

type PosAdjustment

type PosAdjustment struct {
	Offset   int
	ReduceBy int
}

PosAdjustment specifies how much token.Pos's have to be adjusted after different offsets. This is required because to make the pgo source valid Go code, we may have to geneate additional code around it. This will mess up positioning information so we track how much we're affecting the positions and starting at what offsets.

Jump to

Keyboard shortcuts

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