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.
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.
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.
type PosAdjustment ¶
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.