Rust: some basic extraction of function names (with locations!)

This commit is contained in:
Paolo Tranquilli
2024-08-29 17:03:19 +02:00
parent f40901f391
commit 590a146b49
54 changed files with 1867 additions and 1007 deletions

View File

@@ -1,25 +1,23 @@
// generated by {{generator}}
use crate::trap::{TrapLabel, TrapEntry, quoted};
use crate::trap::{TrapLabel, TrapId, TrapEntry, quoted};
use std::io::Write;
{{#classes}}
#[derive(Debug)]
pub struct {{name}} {
pub key: Option<String>,
pub id: TrapId,
{{#fields}}
pub {{field_name}}: {{type}},
{{/fields}}
}
impl TrapEntry for {{name}} {
type Label = TrapLabel;
fn extract_id(&mut self) -> TrapId {
std::mem::replace(&mut self.id, TrapId::Star)
}
fn prefix() -> &'static str { "{{name}}_" }
fn key(&self) -> Option<&str> { self.key.as_ref().map(String::as_str) }
fn emit<W: Write>(&self, id: &Self::Label, out: &mut W) -> std::io::Result<()> {
fn emit<W: Write>(self, id: TrapLabel, out: &mut W) -> std::io::Result<()> {
write!(out, "{{table_name}}({id}{{#single_fields}}, {}{{/single_fields}})\n"{{#single_fields}}, {{#emitter}}self.{{field_name}}{{/emitter}}{{/single_fields}})?;
{{#fields}}
{{#is_predicate}}
@@ -50,5 +48,4 @@ impl TrapEntry for {{name}} {
Ok(())
}
}
{{/classes}}