Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ members = [
"ruby/extractor",
"unified/extractor",
"unified/extractor/tree-sitter-swift",
"unified/swift-syntax-rs",
"rust/extractor",
"rust/extractor/macros",
"rust/ast-generator",
Expand Down
37 changes: 36 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,20 @@ bazel_dep(name = "rules_python", version = "1.9.0")
bazel_dep(name = "rules_shell", version = "0.7.1")
bazel_dep(name = "bazel_skylib", version = "1.9.0")
bazel_dep(name = "abseil-cpp", version = "20260107.1", repo_name = "absl")
bazel_dep(name = "nlohmann_json", version = "3.11.3", repo_name = "json")
bazel_dep(name = "nlohmann_json", version = "3.12.0.bcr.1", repo_name = "json")
bazel_dep(name = "fmt", version = "12.1.0-codeql.1")
bazel_dep(name = "rules_kotlin", version = "2.2.2-codeql.1")
bazel_dep(name = "gazelle", version = "0.50.0")
bazel_dep(name = "rules_dotnet", version = "0.21.5-codeql.1")
bazel_dep(name = "googletest", version = "1.17.0.bcr.2")
bazel_dep(name = "rules_rust", version = "0.69.0")
bazel_dep(name = "rules_swift", version = "4.0.0-rc4")
bazel_dep(name = "swift-syntax", version = "603.0.2")

# Needed so we can `use_repo` `local_config_xcode` and
# `local_config_apple_cc_toolchains` below (referenced by the per-target
# Xcode-config transition in `unified/swift-syntax-rs/xcode_transition.bzl`).
bazel_dep(name = "apple_support", version = "2.6.1")
bazel_dep(name = "zstd", version = "1.5.7.bcr.1")

bazel_dep(name = "buildifier_prebuilt", version = "6.4.0", dev_dependency = True)
Expand Down Expand Up @@ -219,6 +226,34 @@ use_repo(
"swift-resource-dir-macos",
)

# Swift toolchain for building `unified/swift-syntax-rs`. On Linux we register
# a hermetic swift.org toolchain as the exec toolchain; on macOS `rules_swift`
# auto-registers `xcode_swift_toolchain` (host Xcode + OS-provided Swift
# runtime), which is not hermetic. Version comes from
# `unified/swift-syntax-rs/.swift-version`.
swift = use_extension("@rules_swift//swift:extensions.bzl", "swift")
swift.toolchain(
name = "swift_toolchain",
swift_version_file = "//unified/swift-syntax-rs:.swift-version",
)
use_repo(
swift,
"swift_toolchain",
"swift_toolchain_ubuntu24.04",
)

register_toolchains(
"@swift_toolchain//:swift_toolchain_exec_ubuntu24.04",
)

# `apple_support`'s xcode_config and CC toolchains, needed by the Xcode
# transition in `unified/swift-syntax-rs/xcode_transition.bzl`.
xcode_configure = use_extension("@apple_support//xcode:xcode_configure.bzl", "xcode_configure_extension")
use_repo(xcode_configure, "local_config_xcode")

apple_cc_configure = use_extension("@apple_support//crosstool:setup.bzl", "apple_cc_configure_extension")
use_repo(apple_cc_configure, "local_config_apple_cc_toolchains")

node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node")
node.toolchain(
name = "nodejs",
Expand Down
12 changes: 10 additions & 2 deletions shared/tree-sitter-extractor/src/extractor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,18 @@ impl AstNode for yeast::Node {
yeast::Node::is_extra(self)
}
fn start_position(&self) -> tree_sitter::Point {
yeast::Node::start_position(self)
let p = yeast::Node::start_position(self);
tree_sitter::Point {
row: p.row,
column: p.column,
}
}
fn end_position(&self) -> tree_sitter::Point {
yeast::Node::end_position(self)
let p = yeast::Node::end_position(self);
tree_sitter::Point {
row: p.row,
column: p.column,
}
}
fn byte_range(&self) -> std::ops::Range<usize> {
yeast::Node::byte_range(self)
Expand Down
2 changes: 1 addition & 1 deletion shared/yeast-macros/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ pub fn parse_rule_top(input: TokenStream) -> Result<TokenStream> {
Ok(quote! {
{
let __query = #query_code;
yeast::Rule::new(__query, Box::new(|__ast: &mut yeast::Ast, mut __captures: yeast::captures::Captures, __fresh: &yeast::tree_builder::FreshScope, __source_range: Option<tree_sitter::Range>, __user_ctx: &mut _, __translator: yeast::TranslatorHandle<'_, _>| {
yeast::Rule::new(__query, Box::new(|__ast: &mut yeast::Ast, mut __captures: yeast::captures::Captures, __fresh: &yeast::tree_builder::FreshScope, __source_range: Option<yeast::Range>, __user_ctx: &mut _, __translator: yeast::TranslatorHandle<'_, _>| {
// Auto-translation prefix: recursively translate every
// captured node before invoking the user's transform body,
// except for `@@name` captures listed in `__skip` which the
Expand Down
22 changes: 22 additions & 0 deletions shared/yeast-schema/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,28 @@ impl Schema {
id
}

/// Register every kind (named and unnamed) and field *name* from `other`
/// into this schema (idempotent). Ids are assigned in this schema's own id
/// space; existing ids are unchanged.
///
/// This is used when running desugaring rules over an AST that was built
/// against a different schema (e.g. from an external parser): the rules
/// build output nodes whose kind/field names come from `other`, and those
/// names must resolve in the AST's own schema. Only names are needed — the
/// rule engine resolves kinds/fields by name and does not consult
/// `other`'s field-type or supertype information.
pub fn register_names_from(&mut self, other: &Schema) {
for name in other.kind_ids.keys() {
self.register_kind(name);
}
for name in other.unnamed_kind_ids.keys() {
self.register_unnamed_kind(name);
}
for name in other.field_ids.keys() {
self.register_field(name);
}
}

/// Track a name for a kind ID without registering it as named or
/// unnamed. Useful when importing tree-sitter ID tables that may
/// contain duplicate IDs across the named/unnamed split.
Expand Down
10 changes: 5 additions & 5 deletions shared/yeast/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::BTreeMap;

use crate::captures::Captures;
use crate::tree_builder::FreshScope;
use crate::{Ast, FieldId, Id, NodeContent, TranslatorHandle};
use crate::{Ast, FieldId, Id, NodeContent, Range, TranslatorHandle};

/// Context for building new AST nodes during a transformation.
///
Expand Down Expand Up @@ -34,7 +34,7 @@ pub struct BuildCtx<'a, C: 'a = ()> {
pub captures: &'a Captures,
pub fresh: &'a FreshScope,
/// Source range of the matched node, inherited by synthetic nodes.
pub source_range: Option<tree_sitter::Range>,
pub source_range: Option<Range>,
/// User-supplied context, accessible directly via `ctx.field` (via Deref).
pub user_ctx: &'a mut C,
/// Optional translator handle, populated when the context is built by
Expand Down Expand Up @@ -63,7 +63,7 @@ impl<'a, C> BuildCtx<'a, C> {
ast: &'a mut Ast,
captures: &'a Captures,
fresh: &'a FreshScope,
source_range: Option<tree_sitter::Range>,
source_range: Option<Range>,
user_ctx: &'a mut C,
) -> Self {
Self {
Expand All @@ -82,7 +82,7 @@ impl<'a, C> BuildCtx<'a, C> {
ast: &'a mut Ast,
captures: &'a Captures,
fresh: &'a FreshScope,
source_range: Option<tree_sitter::Range>,
source_range: Option<Range>,
user_ctx: &'a mut C,
translator: TranslatorHandle<'a, C>,
) -> Self {
Expand Down Expand Up @@ -143,7 +143,7 @@ impl<'a, C> BuildCtx<'a, C> {
&mut self,
kind: &'static str,
value: &str,
source_range: Option<tree_sitter::Range>,
source_range: Option<Range>,
) -> Id {
self.ast.create_named_token_with_range(
kind,
Expand Down
Loading
Loading