pgo

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

Documentation

Overview

Package pgo defines a superset of the Go syntax and provides the ability to parse and manipulate it. pgo is used to parse versions of a gopatch change.

Key features of pgo are:

  • package names are optional
  • expressions and statements may be written at the top level
  • ... is supported in a number of places

Syntax

The following documents the syntax for pgo, assuming the syntax for Go is already provided under the "go." namespace.

// Package names and imports are optional. Only a single top-level
// declaration is allowed.
file = package? imports decl;
package = "package" go.package_name;

// import_decl is a standard Go import declarations.
imports = go.import_decl*;

// For top-level declarations, type, function/method, and constant
// declarations are assumed to be standard Go declarations. In addition to
// them, statement lists and expressions are supported at the top-level.
decl
  = go.type_decl
  | go.func_decl
  | go.const_decl
  | stmt_list
  | go.expr;

// Statement lists can open with curly braces or as-is. The two cases are
// necessary to allow disambiguating between top-level type/const
// declarations and those inlined inside a code block.
stmt_list = '{' go.stmt* '}' | go.stmt+;

Dots

"...", referred to as "dots" is accepted anywhere as a statement and an expression. Note that pgo doesn't ascribe any meaning to these dots but gopatch may.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dots

type Dots struct {
	ast.Expr

	Dots token.Pos // position of dots
}

Dots is a "..." used as an expression.

If used as a statement, Dots will be inside an ExprStmt.

func (*Dots) End

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

End returns the position after "...".

func (*Dots) Pos

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

Pos returns the start position of "...".

type Expr

type Expr struct{ ast.Expr }

Expr is a Go expression at the top-level in pgo.

type File

type File struct {
	// Package name specified in the file, if any.
	Package string

	// Imports made in the source.
	Imports []*ast.ImportSpec

	// Comments declared in the file.
	Comments []*ast.CommentGroup

	// Top-level node declared in the file.
	//
	// pgo allows only one node at the top-level. It must be either a standard
	// Go top-level declaration, an expression, or a list of statements.
	Node Node
}

File is a single pgo file. This is analogous to go/ast's File.

func Parse

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

Parse parses a pgo file. AST nodes in the returned File reference a newly added token.File in the given FileSet.

type FuncDecl

type FuncDecl struct{ *ast.FuncDecl }

FuncDecl is a Go function declaration at the top-level in pgo.

type GenDecl

type GenDecl struct{ *ast.GenDecl }

GenDecl is a Go general declaration at the top-level in pgo.

type Node

type Node interface {
	ast.Node
	// contains filtered or unexported methods
}

Node unifies the custom node types we introduce to the Go AST.

type StmtList

type StmtList struct {
	List []ast.Stmt // inv: len > 0
}

StmtList is a list of statements at the top-level of a pgo file.

func (*StmtList) End

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

End returns the position of the character immediately after this statement list, or NoPos if there are no statements in this list.

func (*StmtList) Pos

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

Pos returns the start position of the statement list or NoPos if there are no statements in it.

Directories

Path Synopsis
Package augment facilitates adding syntax to the Go AST.
Package augment facilitates adding syntax to the Go AST.

Jump to

Keyboard shortcuts

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