Skip to content

Commit 1fb4f9d

Browse files
committed
yeast: Move schema and YAML loader into yeast-schema crate
For type checking rules, we need to be able to load schemas (so we know what to check against). However, since we can't have yeast-macros depending on yeast (where the schema-handling code currently lives) as this would introduce a circular dependency, we instead split the schema-related code into its own yeast-schema crate.
1 parent 33da3ef commit 1fb4f9d

13 files changed

Lines changed: 1275 additions & 1047 deletions

File tree

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ members = [
66
"shared/tree-sitter-extractor",
77
"shared/yeast",
88
"shared/yeast-macros",
9+
"shared/yeast-schema",
910
"ruby/extractor",
1011
"unified/extractor",
1112
"unified/extractor/tree-sitter-swift",

misc/bazel/3rdparty/tree_sitter_extractors_deps/defs.bzl

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shared/yeast-schema/BUILD.bazel

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
load("@rules_rust//rust:defs.bzl", "rust_library")
2+
load("//misc/bazel/3rdparty/tree_sitter_extractors_deps:defs.bzl", "aliases", "all_crate_deps")
3+
4+
exports_files(["Cargo.toml"])
5+
6+
rust_library(
7+
name = "yeast-schema",
8+
srcs = glob(["src/**/*.rs"]),
9+
aliases = aliases(),
10+
visibility = ["//visibility:public"],
11+
deps = all_crate_deps(),
12+
)

shared/yeast-schema/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "yeast-schema"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
serde = { version = "1.0", features = ["derive"] }
8+
serde_json = "1.0"
9+
serde_yaml = "0.9"

shared/yeast-schema/src/lib.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//! Schema definitions and YAML/JSON node-types loaders for YEAST.
2+
//!
3+
//! This crate carries the parts of the YEAST framework that don't need
4+
//! `tree-sitter`: the [`schema::Schema`] type and its associated
5+
//! [`schema::NodeType`] / [`schema::FieldCardinality`] helpers, plus the
6+
//! YAML and JSON conversion helpers in [`node_types_yaml`].
7+
//!
8+
//! It exists so that both the runtime crate (`yeast`) and the
9+
//! compile-time `rules!` proc macro (`yeast-macros`) can build against a
10+
//! single source of truth without dragging tree-sitter (a heavy C-backed
11+
//! dep) into the proc-macro toolchain.
12+
//!
13+
//! Tree-sitter-aware adapters — building a `Schema` from a
14+
//! `tree_sitter::Language`, or loading a YAML schema on top of one —
15+
//! live in `yeast::schema` and `yeast::node_types_yaml` respectively.
16+
17+
pub mod node_types_yaml;
18+
pub mod schema;
19+
20+
/// Field IDs are stable `u16`s, matching tree-sitter's representation so a
21+
/// schema built from a tree-sitter language can preserve the language's
22+
/// existing IDs.
23+
pub type FieldId = u16;
24+
25+
/// Kind IDs are stable `u16`s. Like `FieldId`, this matches tree-sitter's
26+
/// representation.
27+
pub type KindId = u16;
28+
29+
/// Sentinel field id used to mean "the implicit unfielded slot" (what the
30+
/// tree-sitter docs call `children` and what YEAST surfaces in queries as
31+
/// the bare `child:` field). Reserved to avoid clashing with real field
32+
/// IDs allocated by `Schema::register_field`.
33+
pub const CHILD_FIELD: u16 = u16::MAX;

0 commit comments

Comments
 (0)