section

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

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Change

type Change struct {
	// Position at which the first @ of the header occurs.
	HeaderPos token.Pos

	// Changes can optionally have a name.
	//
	// If any, it is specified between the first pair of @@s in the change.
	Name string

	// Metavariables section of the change.
	Meta Section

	// Position of the second "@@".
	AtPos token.Pos

	// Patch is the patch section of the change. This is the code after the
	// second @@.
	Patch Section

	// Comments in the patch
	Comments []string
}

Change is a single change in a program.

func (*Change) End

func (c *Change) End() token.Pos

End returns the position of the first character after this change.

func (*Change) Pos

func (c *Change) Pos() token.Pos

Pos returns the position at which this change begins.

type Line

type Line struct {
	// Position at which this line begins.
	StartPos token.Pos

	// Contents of the line.
	Text []byte
}

Line is a single line from the patch.

func (*Line) End

func (l *Line) End() token.Pos

End returns the position of the character just past this line.

func (*Line) Pos

func (l *Line) Pos() token.Pos

Pos returns the position at which this line begins.

type LinePos

type LinePos struct {
	// Offset of the first character of this line.
	Offset int

	// Original position from which this line was extracted.
	Pos token.Pos
}

LinePos contains positional information about a line in a buffer.

func ToBytes

func ToBytes(s Section) (src []byte, lines []LinePos)

ToBytes converts a Section to its raw byte contents. A sorted list mapping offsets in the returned byte slice to original token.Pos values is included in the response.

type Program

type Program []*Change

Program is a single .patch file consisting of one or more changes.

func Split

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

Split splits a Program into sections.

type Section

type Section []*Line

Section is a section of the change.

Jump to

Keyboard shortcuts

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