Escape reserved keywords in generate
This commit escapes certain (hopefully all keywords present in snapshot1!) reserved keywords in Rust that are autogenerated by wiggle.
This commit is contained in:
@@ -77,6 +77,8 @@ impl Names {
|
|||||||
// FIXME this is a hack - just a proof of concept.
|
// FIXME this is a hack - just a proof of concept.
|
||||||
if id.as_str().starts_with('2') {
|
if id.as_str().starts_with('2') {
|
||||||
format_ident!("TooBig")
|
format_ident!("TooBig")
|
||||||
|
} else if id.as_str() == "type" {
|
||||||
|
format_ident!("Type")
|
||||||
} else {
|
} else {
|
||||||
format_ident!("{}", id.as_str().to_camel_case())
|
format_ident!("{}", id.as_str().to_camel_case())
|
||||||
}
|
}
|
||||||
@@ -91,8 +93,13 @@ impl Names {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn struct_member(&self, id: &Id) -> Ident {
|
pub fn struct_member(&self, id: &Id) -> Ident {
|
||||||
|
// FIXME this is a hack - just a proof of concept.
|
||||||
|
if id.as_str() == "type" {
|
||||||
|
format_ident!("type_")
|
||||||
|
} else {
|
||||||
format_ident!("{}", id.as_str().to_snake_case())
|
format_ident!("{}", id.as_str().to_snake_case())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn module(&self, id: &Id) -> Ident {
|
pub fn module(&self, id: &Id) -> Ident {
|
||||||
format_ident!("{}", id.as_str().to_snake_case())
|
format_ident!("{}", id.as_str().to_snake_case())
|
||||||
@@ -107,8 +114,13 @@ impl Names {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn func_param(&self, id: &Id) -> Ident {
|
pub fn func_param(&self, id: &Id) -> Ident {
|
||||||
|
// FIXME this is a hack - just a proof of concept.
|
||||||
|
if id.as_str() == "in" {
|
||||||
|
format_ident!("in_")
|
||||||
|
} else {
|
||||||
format_ident!("{}", id.as_str().to_snake_case())
|
format_ident!("{}", id.as_str().to_snake_case())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// For when you need a {name}_ptr binding for passing a value by reference:
|
/// For when you need a {name}_ptr binding for passing a value by reference:
|
||||||
pub fn func_ptr_binding(&self, id: &Id) -> Ident {
|
pub fn func_ptr_binding(&self, id: &Id) -> Ident {
|
||||||
|
|||||||
Reference in New Issue
Block a user