modfile

package standard library
go1.11beta1 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2018 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoQuote

func AutoQuote(s string) string

AutoQuote returns s or, if quoting is required for s to appear in a go.mod, the quotation of s.

func Format

func Format(f *FileSyntax) []byte

func ParseGopkgIn

func ParseGopkgIn(path string) (root, repo, major, subdir string, ok bool)

ParseGopkgIn splits gopkg.in import paths into their constituent parts

Types

type Comment

type Comment struct {
	Start  Position
	Token  string // without trailing newline
	Suffix bool   // an end of line (not whole line) comment
}

A Comment represents a single // comment.

type CommentBlock

type CommentBlock struct {
	Comments
	Start Position
}

A CommentBlock represents a top-level block of comments separate from any rule.

func (*CommentBlock) Span

func (x *CommentBlock) Span() (start, end Position)

type Comments

type Comments struct {
	Before []Comment // whole-line comments before this expression
	Suffix []Comment // end-of-line comments after this expression

	// For top-level expressions only, After lists whole-line
	// comments following the expression.
	After []Comment
}

Comments collects the comments associated with an expression.

func (*Comments) Comment

func (c *Comments) Comment() *Comments

Comment returns the receiver. This isn't useful by itself, but a Comments struct is embedded into all the expression implementation types, and this gives each of those a Comment method to satisfy the Expr interface.

type Exclude

type Exclude struct {
	Mod    module.Version
	Syntax *Line
}

type Expr

type Expr interface {
	// Span returns the start and end position of the expression,
	// excluding leading or trailing comments.
	Span() (start, end Position)

	// Comment returns the comments attached to the expression.
	// This method would normally be named 'Comments' but that
	// would interfere with embedding a type of the same name.
	Comment() *Comments
}

An Expr represents an input element.

type File

type File struct {
	Module  *Module
	Require []*Require
	Exclude []*Exclude
	Replace []*Replace

	Syntax *FileSyntax
}

func Parse

func Parse(file string, data []byte, fix VersionFixer) (*File, error)

func (*File) AddComment

func (f *File) AddComment(text string)

func (*File) AddModuleStmt

func (f *File) AddModuleStmt(path string)

func (*File) AddRequire

func (x *File) AddRequire(path, vers string)

func (*File) Format

func (f *File) Format() ([]byte, error)

func (*File) SetRequire

func (f *File) SetRequire(req []module.Version)

func (*File) SortBlocks

func (f *File) SortBlocks()

type FileSyntax

type FileSyntax struct {
	Name string // file path
	Comments
	Stmt []Expr
}

A FileSyntax represents an entire go.mod file.

func (*FileSyntax) Span

func (x *FileSyntax) Span() (start, end Position)

type LParen

type LParen struct {
	Comments
	Pos Position
}

An LParen represents the beginning of a parenthesized line block. It is a place to store suffix comments.

func (*LParen) Span

func (x *LParen) Span() (start, end Position)

type Line

type Line struct {
	Comments
	Start Position
	Token []string
	End   Position
}

A Line is a single line of tokens.

func (*Line) Span

func (x *Line) Span() (start, end Position)

type LineBlock

type LineBlock struct {
	Comments
	Start  Position
	LParen LParen
	Token  []string
	Line   []*Line
	RParen RParen
}

A LineBlock is a factored block of lines, like

require (
	"x"
	"y"
)

func (*LineBlock) Span

func (x *LineBlock) Span() (start, end Position)

type Module

type Module struct {
	Mod   module.Version
	Major string
}

type Position

type Position struct {
	Line     int // line in input (starting at 1)
	LineRune int // rune in line (starting at 1)
	Byte     int // byte in input (starting at 0)
}

A Position describes the position between two bytes of input.

type RParen

type RParen struct {
	Comments
	Pos Position
}

An RParen represents the end of a parenthesized line block. It is a place to store whole-line (before) comments.

func (*RParen) Span

func (x *RParen) Span() (start, end Position)

type Replace

type Replace struct {
	Old module.Version
	New module.Version

	Syntax *Line
}

type Require

type Require struct {
	Mod    module.Version
	Syntax *Line
}

type VersionFixer

type VersionFixer func(path, version string) (string, error)

Jump to

Keyboard shortcuts

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