gop

package module
v1.2.6 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: Apache-2.0 Imports: 32 Imported by: 242

README

Build Status Go Report Card Coverage Status GitHub release Discord

Our vision is to enable everyone to create production-level applications.

Easy to learn

  • Simple and easy to understand
  • Smaller syntax set than Python in best practices

Ready for large projects

  • Derived from Go and easy to build large projects from its good engineering foundation

The Go+ programming language is designed for engineering, STEM education, and data science.

  • For engineering: working in the simplest language that can be mastered by children.
  • For STEM education: studying an engineering language that can be used for work in the future.
  • For data science: communicating with engineers in the same language.

For more details, see Quick Start.

Command Style Code

Different from the function call style of most languages, Go+ recommends command style code:

println "Hello world"

To emphasize our preference for command style, we introduce echo as an alias for println:

echo "Hello world"

For more discussion on coding style, see https://tutorial.goplus.org/hello-world.

Go+ Classfiles

One language can change the whole world.
Go+ is a "DSL" for all domains.

Rob Pike once said that if he could only introduce one feature to Go, he would choose interface instead of goroutine. classfile is as important to Go+ as interface is to Go.

In the design philosophy of Go+, we do not recommend DSL (Domain Specific Language). But SDF (Specific Domain Friendliness) is very important. The Go+ philosophy about SDF is:

Don't define a language for specific domain.
Abstract domain knowledge for it.

Go+ introduces classfile to abstract domain knowledge.

Sound a bit abstract? Let's see some Go+ classfiles.

yap: Yet Another HTTP Web Framework

This classfile has the file suffix .yap.

Create a file named get.yap with the following content:

html `<html><body>Hello, YAP!</body></html>`

Execute the following commands:

gop mod init hello
gop get github.com/goplus/yap@latest
gop mod tidy
gop run .

A simplest web program is running now. At this time, if you visit http://localhost:8080, you will get:

Hello, YAP!

YAP uses filenames to define routes. get.yap's route is get "/" (GET homepage), and get_p_#id.yap's route is get "/p/:id" (In fact, the filename can also be get_p_:id.yap, but it is not recommended because : is not allowed to exist in filenames under Windows).

Let's create a file named get_p_#id.yap with the following content:

json {
	"id": ${id},
}

Execute gop run . and visit http://localhost:8080/p/123, you will get:

{"id": "123"}

See yap: Yet Another HTTP Web Framework for more details.

spx: A Go+ 2D Game Engine

Screen Shot1 Screen Shot2

Through this example you can learn how to implement dialogues between multiple actors.

Here are some codes in Kai.spx:

onStart => {
	say "Where do you come from?", 2
	broadcast "1"
}

onMsg "2", => {
	say "What's the climate like in your country?", 3
	broadcast "3"
}

We call onStart and onMsg to listen events. onStart is called when the program is started. And onMsg is called when someone calls broadcast to broadcast a message.

When the program starts, Kai says Where do you come from?, and then broadcasts the message 1. Who will recieve this message? Let's see codes in Jaime.spx:

onMsg "1", => {
	say "I come from England.", 2
	broadcast "2"
}

Yes, Jaime recieves the message 1 and says I come from England.. Then he broadcasts the message 2. Kai recieves it and says What's the climate like in your country?.

The following procedures are very similar. In this way you can implement dialogues between multiple actors.

See spx: A Go+ 2D Game Engine for more details.

gsh: Go+ DevOps Tools

Yes, now you can write shell script in Go+. It supports all shell commands.

Let's create a file named example.gsh and write the following code:

mkdir "testgsh"

Don't need a go.mod file, just enter gop run ./example.gsh directly to run.

See gsh: Go+ DevOps Tools for more details.

Key Features of Go+

How to install

on Windows

winget install goplus.gop

on Debian/Ubuntu

sudo bash -c ' echo "deb [trusted=yes] https://pkgs.goplus.org/apt/ /" > /etc/apt/sources.list.d/goplus.list'
sudo apt update
sudo apt install gop

on RedHat/CentOS/Fedora

sudo bash -c 'echo -e "[goplus]\nname=Go+ Repo\nbaseurl=https://pkgs.goplus.org/yum/\nenabled=1\ngpgcheck=0" > /etc/yum.repos.d/goplus.repo'
sudo yum install gop

on macOS/Linux (Homebrew)

Install via brew

$ brew install goplus

from source code

Note: Requires go1.18 or later

git clone https://github.com/goplus/gop.git
cd gop

# On mac/linux run:
./all.bash
# On Windows run:
all.bat

Go+ Applications

2D Games powered by Go+

Web Programming

DevOps Tools

Data Processing

IDE Plugins

Contributing

The Go+ project welcomes all contributors. We appreciate your help!

For more details, see Contributing & compiler design.

Give a Star! ⭐

If you like or are using Go+ to learn or start your projects, please give it a star. Thanks!

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound      = gopmod.ErrNotFound
	ErrIgnoreNotated = errors.New("notated error ignored")
)
View Source
var (
	ErrMultiPackges     = errors.New("multiple packages")
	ErrMultiTestPackges = errors.New("multiple test packages")
)

Functions

func BuildDir added in v1.1.0

func BuildDir(dir string, conf *Config, build *gocmd.BuildConfig, flags ...GenFlags) (err error)

BuildDir builds a Go+ package directory.

func BuildFiles added in v1.1.0

func BuildFiles(files []string, conf *Config, build *gocmd.BuildConfig) (err error)

BuildFiles builds specified Go+ files.

func BuildPkgPath added in v1.1.0

func BuildPkgPath(workDir, pkgPath string, conf *Config, build *gocmd.BuildConfig, flags ...GenFlags) (err error)

BuildPkgPath builds a Go+ package.

func ErrorPos added in v1.1.10

func ErrorPos(err error) token.Pos

ErrorPos returns where the error occurs.

func FilterNoTestFiles added in v1.2.2

func FilterNoTestFiles(fi fs.FileInfo) bool

FilterNoTestFiles filters to skip all testing files.

func GenGo added in v1.1.0

func GenGo(dir string, conf *Config, genTestPkg bool) (string, bool, error)

GenGo generates gop_autogen.go for a Go+ package directory.

func GenGoEx added in v1.1.8

func GenGoEx(dir string, conf *Config, genTestPkg bool, flags GenFlags) (string, bool, error)

GenGoEx generates gop_autogen.go for a Go+ package directory.

func GenGoFiles added in v1.1.0

func GenGoFiles(autogen string, files []string, conf *Config) (outFiles []string, err error)

GenGoFiles generates gop_autogen.go for specified Go+ files.

func GenGoPkgPath added in v1.1.0

func GenGoPkgPath(workDir, pkgPath string, conf *Config, allowExtern bool) (localDir string, recursively bool, err error)

GenGoPkgPath generates gop_autogen.go for a Go+ package.

func GenGoPkgPathEx added in v1.1.8

func GenGoPkgPathEx(workDir, pkgPath string, conf *Config, allowExtern bool, flags GenFlags) (localDir string, recursively bool, err error)

GenGoPkgPathEx generates gop_autogen.go for a Go+ package.

func GetFileClassType added in v1.2.6

func GetFileClassType(mod *gopmod.Module, file *ast.File, filename string) (classType string, isTest bool, ok bool)

GetFileClassType get gop module file classType.

func IgnoreNotated added in v1.1.10

func IgnoreNotated(err error) bool

IgnoreNotated returns if cause err is ErrIgnoreNotated or not.

func InstallDir added in v1.1.0

func InstallDir(dir string, conf *Config, install *gocmd.InstallConfig, flags ...GenFlags) (err error)

InstallDir installs a Go+ package directory.

func InstallFiles added in v1.1.0

func InstallFiles(files []string, conf *Config, install *gocmd.InstallConfig) (err error)

InstallFiles installs specified Go+ files.

func InstallPkgPath added in v1.1.0

func InstallPkgPath(workDir, pkgPath string, conf *Config, install *gocmd.InstallConfig, flags ...GenFlags) (err error)

InstallPkgPath installs a Go+ package.

func LoadDir added in v1.1.0

func LoadDir(dir string, conf *Config, genTestPkg bool, promptGenGo ...bool) (out, test *gogen.Package, err error)

LoadDir loads Go+ packages from a specified directory.

func LoadFiles added in v1.1.0

func LoadFiles(dir string, files []string, conf *Config) (out *gogen.Package, err error)

LoadDir loads a Go+ package from specified files.

func LoadMod added in v1.1.5

func LoadMod(dir string) (mod *gopmod.Module, err error)

LoadMod loads a Go+ module from a specified directory.

func NotFound added in v1.1.2

func NotFound(err error) bool

NotFound returns if cause err is ErrNotFound or not

func Outline added in v1.1.8

func Outline(dir string, conf *Config) (out outline.Package, err error)

func OutlinePkgPath added in v1.1.8

func OutlinePkgPath(workDir, pkgPath string, conf *Config, allowExtern bool) (out outline.Package, err error)

func RunDir added in v1.1.0

func RunDir(dir string, args []string, conf *Config, run *gocmd.RunConfig, flags ...GenFlags) (err error)

RunDir runs an application from a Go+ package directory.

func RunFiles added in v1.1.0

func RunFiles(autogen string, files []string, args []string, conf *Config, run *gocmd.RunConfig) (err error)

RunFiles runs an application from specified Go+ files.

func RunPkgPath added in v1.1.0

func RunPkgPath(pkgPath string, args []string, chDir bool, conf *Config, run *gocmd.RunConfig, flags ...GenFlags) (err error)

RunPkgPath runs an application from a Go+ package.

func TestDir added in v1.1.0

func TestDir(dir string, conf *Config, test *gocmd.TestConfig, flags ...GenFlags) (err error)

TestDir tests a Go+ package directory.

func TestFiles added in v1.1.0

func TestFiles(files []string, conf *Config, test *gocmd.TestConfig) (err error)

TestFiles tests specified Go+ files.

func TestPkgPath added in v1.1.0

func TestPkgPath(workDir, pkgPath string, conf *Config, test *gocmd.TestConfig, flags ...GenFlags) (err error)

TestPkgPath tests a Go+ package.

func Tidy added in v1.1.0

func Tidy(dir string, gop *env.Gop) (err error)

Types

type ConfFlags added in v1.2.6

type ConfFlags int

ConfFlags represents configuration flags.

const (
	ConfFlagIgnoreNotatedError ConfFlags = 1 << iota
	ConfFlagDontUpdateGoMod
	ConfFlagNoTestFiles
	ConfFlagNoCacheFile
)

type Config added in v1.1.0

type Config struct {
	Gop      *env.Gop
	Fset     *token.FileSet
	Mod      *gopmod.Module
	Importer *Importer

	Filter func(fs.FileInfo) bool

	// If not nil, it is used for returning result of checks Go+ dependencies.
	// see https://pkg.go.dev/github.com/goplus/gogen#File.CheckGopDeps
	GopDeps *int

	// CacheFile specifies the file path of the cache.
	CacheFile string

	IgnoreNotatedError bool
	DontUpdateGoMod    bool
}

Config represents a configuration for loading Go+ packages.

func NewDefaultConf added in v1.2.1

func NewDefaultConf(dir string, flags ConfFlags) (conf *Config, err error)

NewDefaultConf creates a dfault configuration for common cases.

func (*Config) UpdateCache added in v1.2.6

func (conf *Config) UpdateCache(verbose ...bool)

UpdateCache updates the cache.

type GenFlags added in v1.1.8

type GenFlags int
const (
	GenFlagCheckOnly GenFlags = 1 << iota
	GenFlagSingleFile
	GenFlagPrintError
	GenFlagPrompt
)

type Importer added in v1.1.0

type Importer struct {
	Flags GenFlags // can change this for loading Go+ modules
	// contains filtered or unexported fields
}

Importer represents a Go+ importer.

func NewImporter added in v1.1.0

func NewImporter(mod *gopmod.Module, gop *env.Gop, fset *token.FileSet) *Importer

NewImporter creates a Go+ Importer.

func (*Importer) Cache added in v1.2.6

func (p *Importer) Cache() *cache.Impl

Cache returns the cache object.

func (*Importer) CacheFile added in v1.2.6

func (p *Importer) CacheFile() string

CacheFile returns file path of the cache.

func (*Importer) Import added in v1.1.0

func (p *Importer) Import(pkgPath string) (pkg *types.Package, err error)

Import imports a Go/Go+ package.

func (*Importer) PkgHash added in v1.2.6

func (p *Importer) PkgHash(pkgPath string, self bool) string

PkgHash calculates hash value for a package. It is required by cache.New func.

Directories

Path Synopsis
ast
Package ast declares the types used to represent syntax trees for Go+ packages.
Package ast declares the types used to represent syntax trees for Go+ packages.
mod
iox
ng
cl
Package cl compiles Go+ syntax trees (ast).
Package cl compiles Go+ syntax trees (ast).
cmd
gop
internal/base
Package base defines shared basic pieces of the gop command, in particular logging and the Command structure.
Package base defines shared basic pieces of the gop command, in particular logging and the Command structure.
internal/build
Package build implements the “gop build” command.
Package build implements the “gop build” command.
internal/gengo
Package gengo implements the “gop go” command.
Package gengo implements the “gop go” command.
internal/gopfmt
Package gopfmt implements the “gop fmt” command.
Package gopfmt implements the “gop fmt” command.
internal/help
Package help implements the “gop help” command.
Package help implements the “gop help” command.
internal/install
Package install implements the “gop install” command.
Package install implements the “gop install” command.
internal/mod
* Copyright (c) 2021 The GoPlus Authors (goplus.org).
* Copyright (c) 2021 The GoPlus Authors (goplus.org).
internal/run
Package run implements the “gop run” command.
Package run implements the “gop run” command.
internal/serve
Package serve implements the “gop serve command.
Package serve implements the “gop serve command.
internal/test
Package test implements the “gop test” command.
Package test implements the “gop test” command.
doc
Package format implements standard formatting of Go+ source.
Package format implements standard formatting of Go+ source.
Package parser implements a parser for Go+ source files.
Package parser implements a parser for Go+ source files.
fsx
Package printer implements printing of AST nodes.
Package printer implements printing of AST nodes.
Package scanner implements a scanner for Go+ source text.
Package scanner implements a scanner for Go+ source text.
Package token defines constants representing the lexical tokens of the Go+ programming language and basic operations on tokens (printing, predicates).
Package token defines constants representing the lexical tokens of the Go+ programming language and basic operations on tokens (printing, predicates).
x
jsonrpc2
Package jsonrpc2 is a minimal implementation of the JSON RPC 2 spec.
Package jsonrpc2 is a minimal implementation of the JSON RPC 2 spec.
jsonrpc2/internal/stack
Package stack provides support for parsing standard goroutine stack traces.
Package stack provides support for parsing standard goroutine stack traces.
watcher
Package watcher monitors code changes in a Go+ workspace.
Package watcher monitors code changes in a Go+ workspace.

Jump to

Keyboard shortcuts

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