parse

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

Documentation

Overview

Package parse provides the ability to parse a .patch file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Change

type Change struct {
	// Name for the change, if any.
	//
	// Names must be valid Go identifiers.
	Name string

	// Metavariables defined for this change.
	Meta *Meta

	// Patch for this change.
	Patch *Patch

	// Comments for this change
	Comments []string
}

Change is a single change in a patch. Changes are specified in the format,

@@
# metavariables go here
@@
# patch goes here

Optionally, a name may be specified for a change between the first two "@@"s.

@ mychange @
# metavariables go here
@@
# patch goes here

type Meta

type Meta struct {
	// Variables declared in this section.
	Vars []*VarDecl
}

Meta represents the metavariables section of a change.

This consists of one or more declarations used in the patch.

type Patch

type Patch struct {
	// Positions at which the entire patch begins and ends.
	StartPos, EndPos token.Pos

	// The before and after versions of the Patch broken apart from the
	// unified diff.
	Minus, Plus *pgo.File
}

Patch is the patch portion of the change containing the unified diff of the match/transformation.

func (*Patch) End

func (p *Patch) End() token.Pos

End returns the position immediately after this patch.

func (*Patch) Pos

func (p *Patch) Pos() token.Pos

Pos returns the position at which this patch begins.

type Program

type Program struct {
	Changes []*Change
}

Program is a single gopatch program consisting of one or more changes.

func Parse

func Parse(fset *token.FileSet, filename string, contents []byte) (*Program, error)

Parse parses a Program.

type VarDecl

type VarDecl struct {
	// Position at which the "var" keyword appears.
	VarPos token.Pos

	// Names of the variables declared in this statement.
	Names []*ast.Ident

	// Type of the variables.
	Type *ast.Ident
}

VarDecl is a single var declaration in a metavariable block.

var foo, bar identifier
var baz, qux expression

func (*VarDecl) End

func (d *VarDecl) End() token.Pos

End returns the position of the next character after this declaration.

func (*VarDecl) Pos

func (d *VarDecl) Pos() token.Pos

Pos returns the position at which this declaration starts.

Directories

Path Synopsis
Package section is responsible for splitting a program into its different sections without attempting to parse the contents.
Package section is responsible for splitting a program into its different sections without attempting to parse the contents.

Jump to

Keyboard shortcuts

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