use fusevm::RustSugar;
fn emit(b64: &str, line: usize) -> String {
format!("__rust_compile(\"{b64}\", {line});")
}
pub const SUGAR: RustSugar = RustSugar {
keyword: "rust",
line_comments: &["//", "#"],
block_comment: Some(("/*", "*/")),
newline_boundary: true,
emit,
};
pub fn desugar(src: &str) -> String {
SUGAR.desugar(src)
}
#[cfg(test)]
mod tests {
#[test]
fn desugars_php_block_after_open_tag() {
let src = "<?php\nrust { pub extern \"C\" fn add(a: i64, b: i64) -> i64 { a + b } }\necho add(2, 3);\n";
let out = super::desugar(src);
assert!(out.contains("__rust_compile("), "no builtin call: {out}");
assert!(!out.contains("pub extern"), "Rust body leaked: {out}");
assert!(out.contains("echo add(2, 3);"));
}
#[test]
fn leaves_ordinary_php_untouched() {
let src = "<?php $x = strlen(\"hi\"); echo $x;\n";
assert_eq!(super::desugar(src), src);
}
}