parser

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package parser parses Go files into an AST that can be easily formatted.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConstDecl

type ConstDecl struct {
	ast.GenDecl
}

type Decl

type Decl interface {
	// contains filtered or unexported methods
}

type File

type File struct {
	Decls []Decl
	// contains filtered or unexported fields
}

File bundles an ast.File and a token.FileSet. It is more convenient to work with than its underlying objects when operating on only one file at a time.

func ParseFile

func ParseFile(name string, src []byte) (*File, error)

ParseFile parses the source code of a single Go source file and returns the corresponding File. The name and src parameters operate as in go/parser.ParseFile.

func (*File) ImportDecls

func (f *File) ImportDecls() []*ImportDecl

func (*File) ImportSpecs

func (f *File) ImportSpecs() []ImportSpec

ImportSpecs returns all the imports specifications from all the import declarations in the file.

func (*File) Offset

func (f *File) Offset(p token.Pos) int

Offset converts a token.Pos into a file offset.

func (*File) Pos

func (f *File) Pos(offset int) token.Pos

Pos converts a file offset into a token.Pos.

func (*File) Position

func (f *File) Position(p token.Pos) token.Position

Position converts a token.Pos into a token.Position.

func (*File) Slice

func (f *File) Slice(start, end token.Pos) []byte

Slice returns the bytes in the range [start, end).

type FuncDecl

type FuncDecl struct {
	ast.FuncDecl
}

func (*FuncDecl) BodyEnd

func (f *FuncDecl) BodyEnd() token.Pos

BodyEnd returns the end position of the function's body.

type ImportDecl

type ImportDecl struct {
	Doc      *ast.CommentGroup
	Specs    []ImportSpec
	Pos, End token.Pos
}

ImportDecl represents an import declaration in a File.

type ImportSpec

type ImportSpec struct {
	ast.ImportSpec
}

ImportSpec represents an import specification in an ImportDecl.

func (*ImportSpec) Path

func (i *ImportSpec) Path() string

type TypeDecl

type TypeDecl struct {
	ast.GenDecl
}

type VarDecl

type VarDecl struct {
	ast.GenDecl
}

Jump to

Keyboard shortcuts

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