Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Starlark in Go: the Starlark configuration language, implemented in Go

License

NotificationsYou must be signed in to change notification settings

google/starlark-go

Go TestsGo Reference

This is the home of theStarlark in Go project.Starlark in Go is an interpreter for Starlark, implemented in Go.Starlark was formerly known as Skylark.The import path for the Go package is"go.starlark.net/starlark".

Starlark is a dialect of Python intended for use as a configuration language.Like Python, it is an untyped dynamic language with high-level datatypes, first-class functions with lexical scope, and garbage collection.Unlike CPython, independent Starlark threads execute in parallel, soStarlark workloads scale well on parallel machines.Starlark is a small and simple language with a familiar and highlyreadable syntax. You can use it as an expressive notation forstructured data, defining functions to eliminate repetition, or youcan use it to add scripting capabilities to an existing application.

A Starlark interpreter is typically embedded within a largerapplication, and the application may define additional domain-specificfunctions and data types beyond those provided by the core language.For example, Starlark was originally developed for theBazel build tool.Bazel uses Starlark as the notation both for its BUILD files (likeMakefiles, these declare the executables, libraries, and tests in adirectory) and forits macrolanguage,through which Bazel is extended with custom logic to support newlanguages and compilers.

Documentation

Getting started

Build the code:

# check out the code and dependencies,# and install interpreter in $GOPATH/bin$ go install go.starlark.net/cmd/starlark@latest

Run the interpreter:

$cat coins.starcoins = {  'dime': 10,  'nickel': 5,  'penny': 1,  'quarter': 25,}print('By name:\t' + ', '.join(sorted(coins.keys())))print('By value:\t' + ', '.join(sorted(coins.keys(), key=coins.get)))$starlark coins.starBy name:dime, nickel, penny, quarterBy value:penny, nickel, dime, quarter

Interact with the read-eval-print loop (REPL):

$ starlark>>>deffibonacci(n):...    res=list(range(n))...for iin res[2:]:...        res[i]= res[i-2]+ res[i-1]...return res...>>> fibonacci(10)[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]>>>

When you have finished, typeCtrl-D to close the REPL's input stream.

Embed the interpreter in your Go program:

import"go.starlark.net/starlark"// Execute Starlark program in a file.thread:=&starlark.Thread{Name:"my thread"}globals,err:=starlark.ExecFile(thread,"fibonacci.star",nil,nil)iferr!=nil {... }// Retrieve a module global.fibonacci:=globals["fibonacci"]// Call Starlark function from Go.v,err:=starlark.Call(thread,fibonacci, starlark.Tuple{starlark.MakeInt(10)},nil)iferr!=nil {... }fmt.Printf("fibonacci(10) = %v\n",v)// fibonacci(10) = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]

Seestarlark/example_test.go for more examples.

Contributing

We welcome submissions but please let us know what you're working onif you want to change or add to the Starlark repository.

Before undertaking to write something new for the Starlark project,please file an issue or claim an existing issue.All significant changes to the language or to the interpreter's GoAPI must be discussed before they can be accepted.This gives all participants a chance to validate the design and toavoid duplication of effort.

Despite some differences, the Go implementation of Starlark strives tomatch the behavior ofthe Java implementationused by Bazel and maintained by the Bazel team.For that reason, proposals to change the language itself shouldgenerally be directed tothe Starlark site, not to the maintainers of thisproject.Only once there is consensus that a language change is desirable mayits Go implementation proceed.

We use GitHub pull requests for contributions.

Please complete Google's contributor license agreement (CLA) beforesending your first change to the project. If you are the copyrightholder, you will need to agree to theindividual contributor license agreement,which can be completed online.If your organization is the copyright holder, the organization willneed to agree to thecorporate contributor license agreement.If the copyright holder for your contribution has already completedthe agreement in connection with another Google open source project,it does not need to be completed again.

Stability

We reserve the right to make breaking language and API changes at thisstage in the project, although we will endeavor to keep them to a minimum.Once the Bazel team has finalized the version 1 language specification,we will be more rigorous with interface stability.

We aim to support the most recent four (go1.x) releases of the Gotoolchain. For example, if the latest release is go1.20, we support italong with go1.19, go1.18, and go1.17, but not go1.16.

Credits

Starlark was designed and implemented in Java byJon Brandvein,Alan Donovan,Laurent Le Brun,Dmitry Lomov,Vladimir Moskva,François-René Rideau,Gergely Svigruha, andFlorian Weikert,standing on the shoulders of the Python community.The Go implementation was written by Alan Donovan and Jay Conrod;its scanner was derived from one written by Russ Cox.

Legal

Starlark in Go is Copyright (c) 2018 The Bazel Authors.All rights reserved.

It is provided under a 3-clause BSD license:LICENSE.

Starlark in Go is not an official Google product.

About

Starlark in Go: the Starlark configuration language, implemented in Go

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp