astdiff

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: 5 Imported by: 0

Documentation

Overview

Package astdiff provides a means of diffing Go AST nodes that may be mutated in-place by taking snapshots of their state between successive patch executions.

snap := astdiff.Before(node)
modify(node)
snap = snap.Diff(node, changelog)
modify(node)
snap = snap.Diff(node, changelog)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Changelog

type Changelog interface {
	// Changed informs the changelog that the code in the range [pos, end)
	// has been modified.
	Changed(pos, end token.Pos)
}

Changelog records the ranges of positions changed over the course of successive patches.

type Region

type Region struct{ Pos, End token.Pos }

Region denotes the consecutive positions

type Snapshot

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

Snapshot maintains the current view of the ast.Node being altered over the course of patching.

func Before

func Before(n ast.Node, comments ast.CommentMap) *Snapshot

Before starts an AST diff.

Given the unchanged node, it creates a Snapshot of the initial state before applying any patches.

func (*Snapshot) Diff

func (s *Snapshot) Diff(n ast.Node, cl Changelog) *Snapshot

Diff compares the current Snapshot to the altered Node, updates the provided Changelog, and returns an updated Snapshot.

Jump to

Keyboard shortcuts

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