pub const LANGUAGE_REPRESENTATION_SCHEMA_VERSION: u32 = 2;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum RepresentationLevel {
Preserved,
ConcreteSyntax,
Parsed,
Resolved,
Elaborated,
Opaque,
NotApplicable,
Unavailable,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct LanguageSupport {
pub schema_version: u32,
pub name: &'static str,
pub aliases: &'static [&'static str],
pub version: &'static str,
pub edition: &'static str,
pub extensions: &'static [&'static str],
pub source_bytes: RepresentationLevel,
pub concrete_syntax: RepresentationLevel,
pub binding_resolution: RepresentationLevel,
pub type_elaboration: RepresentationLevel,
pub dynamic_extensions: RepresentationLevel,
pub proof_syntax: RepresentationLevel,
pub emitter: &'static str,
}
const fn support(
name: &'static str,
aliases: &'static [&'static str],
version: &'static str,
edition: &'static str,
extensions: &'static [&'static str],
proof_syntax: RepresentationLevel,
) -> LanguageSupport {
LanguageSupport {
schema_version: LANGUAGE_REPRESENTATION_SCHEMA_VERSION,
name,
aliases,
version,
edition,
extensions,
source_bytes: RepresentationLevel::Preserved,
concrete_syntax: RepresentationLevel::ConcreteSyntax,
binding_resolution: RepresentationLevel::Parsed,
type_elaboration: RepresentationLevel::Unavailable,
dynamic_extensions: RepresentationLevel::Parsed,
proof_syntax,
emitter: "ordered source-token emitter",
}
}
pub const FOUR_LANGUAGE_SUPPORT: [LanguageSupport; 4] = [
support(
"JavaScript",
&["javascript", "js", "ecmascript"],
"ECMAScript 2026",
"ECMA-262, 17th edition",
&[".js", ".mjs", ".cjs"],
RepresentationLevel::NotApplicable,
),
support(
"Rust",
&["rust", "rs"],
"Rust 1.99.0",
"2024",
&[".rs"],
RepresentationLevel::NotApplicable,
),
support(
"Lean",
&["lean", "lean4"],
"Lean 4.34.1",
"Lean 4",
&[".lean"],
RepresentationLevel::Parsed,
),
support(
"Rocq",
&["rocq", "coq"],
"Rocq 9.3",
"Vernacular",
&[".v"],
RepresentationLevel::Parsed,
),
];
#[must_use]
pub fn language_support(language: &str) -> Option<&'static LanguageSupport> {
FOUR_LANGUAGE_SUPPORT.iter().find(|support| {
support
.aliases
.iter()
.any(|alias| alias.eq_ignore_ascii_case(language))
})
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum TranslationSupport {
PortableEncoding,
SemanticSubset,
SemanticTranslation,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TranslationContract {
pub schema_version: u32,
pub source: &'static str,
pub target: &'static str,
pub support: TranslationSupport,
pub observation: &'static str,
pub required_runtime: &'static str,
pub encoding: &'static str,
pub assumptions: &'static [&'static str],
pub obligation: Option<String>,
}
#[must_use]
pub fn translation_contracts() -> Vec<TranslationContract> {
FOUR_LANGUAGE_SUPPORT
.iter()
.flat_map(|source| {
FOUR_LANGUAGE_SUPPORT
.iter()
.filter(move |target| target.name != source.name)
.map(move |target| contract(source, target))
})
.collect()
}
#[must_use]
pub fn translation_contract(
source_language: &str,
target_language: &str,
) -> Option<TranslationContract> {
let source = language_support(source_language)?;
let target = language_support(target_language)?;
(source.name != target.name).then(|| contract(source, target))
}
fn contract(source: &LanguageSupport, target: &LanguageSupport) -> TranslationContract {
TranslationContract {
schema_version: LANGUAGE_REPRESENTATION_SCHEMA_VERSION,
source: source.name,
target: target.name,
support: TranslationSupport::PortableEncoding,
observation: "exact source bytes after decoding; target behavior is not preserved",
required_runtime: runtime_for(target.name),
encoding: "meta-language portable source envelope v1 (UTF-8 hexadecimal payload)",
assumptions: &["the source-language runtime is required to execute decoded source"],
obligation: Some(
"semantic translation is not implemented for arbitrary source programs".to_string(),
),
}
}
fn runtime_for(language: &str) -> &'static str {
match language {
"Lean" => "Lean 4.34.1 kernel and project environment",
"Rocq" => "Rocq 9.3 kernel and project environment",
"Rust" => "Rust 1.99.0, edition 2024",
_ => "ECMAScript 2026 host",
}
}