Skip to content
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.ci Add support for set collections, behind a feature (#45) Jan 25, 2019
starlark-repl Support TERM=dumb (#68) Feb 7, 2019
starlark / division is unsupported, only support // division (#69) Feb 10, 2019
.gitignore Base skeleton for this project Jun 25, 2018
.travis.yml Run clippy shard on stable, not nightly (#50) Jan 22, 2019
CONTRIBUTING.md Base skeleton for this project Jun 25, 2018
Cargo.toml Split the crate in 2: starlark and starlark-repl (#24) Dec 17, 2018
LICENSE
README.md Add support for set collections, behind a feature (#45) Jan 25, 2019
rustfmt.toml

README.md

Starlark in Rust

An implementation in Rust of the Starlark language

Build Status

Disclaimer: This is not an officially supported Google product. This project is supported on a best-effort basis and welcome contributions.

Starlark, formerly codenamed Skylark, is a non-Turing complete language based on Python that was made for the Bazel build system to define compilation plugin.

Starlark has at least 3 implementations: a Java one for Bazel, a Go one and this one.

This interpreter was made using the specification from the go version and the Python 3 documentation when things were unclear.

This interpreter does not support most of the go extensions (e.g. bitwise operator or floating point). It optionally includes a set type (by enabling the linked_hash_set feature), as an extension which is not specified in the official Starlark specification, but note that this is just an insertion-order-preserving set, and does not have optimisations for nesting as can be found in the starlark Java implemnetation's depset implementation. It uses signed 64-bit integers.

Usage

You can depend on the starlark crate, it is documented using docs.rs.

A command line interpreter is also provided by this project under starlark-repl, it can interpret files passed at the command line and also start a REPL (Read-Eval-Print Loop). The usage of this program is:

$ starlark-repl --help
[Starlark in Rust interpretor]

Usage: starlark-repl [options] [file1..filen]


Options:
    -b, --build_file    Parse the build file format instead of full Starlark.
    -h, --help          Show the usage of this program.
    -r, --repl          Run a REPL after files have been parsed.

Development

Build

This project build with Cargo. Simply run cargo test to test it, cargo build --release to build a release version and cargo run to run the command-line interpreter.

Possible improvements and optimizations

  • Errors:
    • When an identifier is not found, we can suggest close identifier / keyword.
    • Fix suggestions maybe?
    • Better error spans.
    • Recoverable errors (don't stop at the first error, continue parsing).
  • Evaluation:
    • Static rewrite of the AST before evaluation (e.g. for constant values)
  • Awesome feature:
    • Implement a debugging protocol server side (compatible with the Java one, see (bazelbuild/vscode-bazel#6)).
You can’t perform that action at this time.