use eventb_lsp::server::operator_rows;
pub fn render() -> String {
let mut out = String::new();
out.push_str(
"# Generated by `rossi gen-grammars` from the canonical operator table. Do not edit by hand.\n",
);
out.push_str("OPERATOR_ROWS = [\n");
for row in operator_rows() {
let aliases = row
.aliases
.iter()
.map(|a| py_string(a))
.collect::<Vec<_>>()
.join(", ");
out.push_str(&format!(
" {{\"ascii\": {}, \"unicode\": {}, \"aliases\": [{}], \"symbolic\": {}, \"eager\": {}}},\n",
py_string(&row.ascii),
py_string(&row.unicode),
aliases,
py_bool(row.symbolic),
py_bool(row.eager),
));
}
out.push_str("]\n");
out
}
pub(super) fn py_bool(b: bool) -> &'static str {
if b { "True" } else { "False" }
}
pub(super) fn py_string(s: &str) -> String {
let mut out = String::with_capacity(s.len() + 2);
out.push('"');
for c in s.chars() {
match c {
'\\' => out.push_str("\\\\"),
'"' => out.push_str("\\\""),
'\n' => out.push_str("\\n"),
'\r' => out.push_str("\\r"),
'\t' => out.push_str("\\t"),
_ => out.push(c),
}
}
out.push('"');
out
}