Skip to main content

adze_governance_runtime_profile_core/
lib.rs

1//! Shared parser-feature profile and backend-resolution primitives for runtime consumers.
2//!
3//! This crate intentionally isolates compile-time profile selection so higher-level
4//! governance/reporting crates can focus on matrix and report rendering concerns.
5
6#![forbid(unsafe_op_in_unsafe_fn)]
7#![deny(missing_docs)]
8#![cfg_attr(feature = "strict_api", deny(unreachable_pub))]
9#![cfg_attr(not(feature = "strict_api"), warn(unreachable_pub))]
10#![cfg_attr(feature = "strict_docs", deny(missing_docs))]
11#![cfg_attr(not(feature = "strict_docs"), allow(missing_docs))]
12
13pub use adze_governance_matrix_contract::{ParserBackend, ParserFeatureProfile};
14
15/// Return the compile-time parser feature profile for the runtime crate.
16pub const fn parser_feature_profile_for_runtime() -> ParserFeatureProfile {
17    ParserFeatureProfile::current()
18}
19
20/// Return a parser profile equivalent to the runtime2 `pure-rust-glr` toggle.
21pub const fn parser_feature_profile_for_runtime2(pure_rust_glr: bool) -> ParserFeatureProfile {
22    ParserFeatureProfile {
23        pure_rust: pure_rust_glr,
24        tree_sitter_standard: false,
25        tree_sitter_c2rust: false,
26        glr: pure_rust_glr,
27    }
28}
29
30/// Resolve a backend using an explicit profile.
31pub const fn resolve_backend_for_profile(
32    profile: ParserFeatureProfile,
33    has_conflicts: bool,
34) -> ParserBackend {
35    profile.resolve_backend(has_conflicts)
36}
37
38#[cfg(test)]
39mod tests {
40    use super::*;
41
42    #[test]
43    fn runtime_profile_matches_current_cfg() {
44        assert_eq!(
45            parser_feature_profile_for_runtime().pure_rust,
46            cfg!(feature = "pure-rust")
47        );
48    }
49
50    #[test]
51    fn runtime2_profile_reflects_glr_toggle() {
52        let enabled = parser_feature_profile_for_runtime2(true);
53        assert!(enabled.pure_rust);
54        assert!(enabled.glr);
55        assert!(!enabled.tree_sitter_standard);
56        assert!(!enabled.tree_sitter_c2rust);
57
58        let disabled = parser_feature_profile_for_runtime2(false);
59        assert!(!disabled.pure_rust);
60        assert!(!disabled.glr);
61    }
62
63    #[test]
64    fn resolve_backend_for_profile_delegates_correctly() {
65        let profile = parser_feature_profile_for_runtime2(true);
66        let backend = resolve_backend_for_profile(profile, false);
67        assert_eq!(backend, profile.resolve_backend(false));
68
69        let conflict_backend = resolve_backend_for_profile(profile, true);
70        assert_eq!(conflict_backend, profile.resolve_backend(true));
71    }
72}