Lossless concrete syntax tree for Starlark and the Bazel build language
  • Rust 92.8%
  • Shell 5.4%
  • Starlark 0.8%
  • Nix 0.8%
  • Just 0.2%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Barrett Ruth df46a79aad
All checks were successful
quality / Format (push) Successful in 15s
quality / Lint (push) Successful in 9s
quality / Test (push) Successful in 55s
quality / Release (push) Has been skipped
ci: run dependent jobs after quality instead of polling
2026-09-26 15:31:39 -05:00
.forgejo ci: run dependent jobs after quality instead of polling 2026-09-26 15:31:39 -05:00
corpus/handwritten feat: scaffold the crate 2026-08-25 22:14:58 +10:00
scripts ci: release from a tag with a prepared release pull request 2026-08-26 17:51:16 +10:00
src fix: report lexical errors alongside the token stream (#3) 2026-08-26 22:20:06 +10:00
tests fix: report lexical errors alongside the token stream (#3) 2026-08-26 22:20:06 +10:00
.editorconfig feat: scaffold the crate 2026-08-25 22:14:58 +10:00
.gitignore chore: track only the source, tooling and documentation 2026-08-26 15:50:39 +10:00
Cargo.lock chore: release v0.1.2 (#6) 2026-08-26 22:22:39 +10:00
Cargo.toml docs: link Forgejo repositories [skip ci] 2026-09-21 20:21:58 -05:00
CONTRIBUTING.md docs: link Forgejo repositories [skip ci] 2026-09-21 20:21:58 -05:00
flake.lock feat: scaffold the crate 2026-08-25 22:14:58 +10:00
flake.nix chore: release v0.1.2 (#6) 2026-08-26 22:22:39 +10:00
justfile ci: release from a tag with a prepared release pull request 2026-08-26 17:51:16 +10:00
LICENSE chore: license under GPL-3.0 2026-08-26 15:50:39 +10:00
README.md Update README.md 2026-08-26 17:27:17 +10:00
rust-toolchain.toml docs: restore the lexer invariants as rustdoc 2026-08-26 21:24:07 +10:00
rustfmt.toml feat: scaffold the crate 2026-08-25 22:14:58 +10:00

starlark-cst

Lossless concrete syntax tree for Starlark and the Bazel build language.

use starlark_cst::{Dialect, parse, ast::{AstNode, CallExpr, Expr}};

let parsed = parse("cc_library(name = \"core\", srcs = [\"a.cc\"])\n", Dialect::Bazel);
let call = parsed.syntax().descendants().find_map(CallExpr::cast).unwrap();

assert_eq!(call.callee_name().as_deref(), Some("cc_library"));
let Some(Expr::Literal(name)) = call.arg("name") else { unreachable!() };
assert_eq!(name.string_value().as_deref(), Some("core"));
// The content range excludes the quotes: what a go-to-definition reports.
assert_eq!(name.string_value_range().unwrap(), (19..23).into());

Supported Dialects

bazel-language-servers supports all major (and pre) Bazel 9 dialects:

  • BUILD
  • BUILD.bazel
  • *.bzl
  • MODULE.bazel
  • *.MODULE.bazel
  • REPO.bazel
  • VENDOR.bazel
  • WORKSPACE
  • WORKSPACE.bazel
  • WORKSPACE.bzlmod
  • *.BUILD
  • *.BUILD.bazel
  • *.cquery
  • *.query.bzl
  • *.scl
  • tools/build_rules/prelude_bazel.

See CONTRIBUTING.md.