Public fields for the codegen types
diff --git a/codegen/src/gen.rs b/codegen/src/gen.rs
index 634a07d..58f03fb 100644
--- a/codegen/src/gen.rs
+++ b/codegen/src/gen.rs
@@ -341,7 +341,7 @@
match ty {
types::Type::Box(t) => box_visit(&*t, features, defs, kind, name),
types::Type::Vec(t) => vec_visit(&*t, features, defs, kind, name),
- types::Type::Punctuated(p) => punctuated_visit(p.element(), features, defs, kind, name),
+ types::Type::Punctuated(p) => punctuated_visit(&p.element, features, defs, kind, name),
types::Type::Option(t) => option_visit(&*t, features, defs, kind, name),
types::Type::Tuple(t) => tuple_visit(t, features, defs, kind, name),
types::Type::Token(t) => {
@@ -413,10 +413,10 @@
let mut visit_mut_variants = TokenStream::new();
let mut fold_variants = TokenStream::new();
- for variant in e.variants() {
- let variant_ident = Ident::new(variant.ident(), Span::call_site());
+ for variant in &e.variants {
+ let variant_ident = Ident::new(&variant.ident, Span::call_site());
- if variant.fields().is_empty() {
+ if variant.fields.is_empty() {
visit_variants.append_all(quote! {
#ty::#variant_ident => {}
});
@@ -437,7 +437,7 @@
let mut visit_mut_fields = TokenStream::new();
let mut fold_fields = TokenStream::new();
- for (idx, ty) in variant.fields().iter().enumerate() {
+ for (idx, ty) in variant.fields.iter().enumerate() {
let name = format!("_binding_{}", idx);
let binding = Ident::new(&name, Span::call_site());
@@ -515,20 +515,20 @@
types::Node::Struct(ref v) => {
let mut fold_fields = TokenStream::new();
- for (field, ty) in v.fields() {
- let id = Ident::new(field, Span::call_site());
+ for (field, ty) in &v.fields {
+ let id = Ident::new(&field, Span::call_site());
let ref_toks = Owned(quote!(_i.#id));
- let visit_field = visit(ty, v.features(), defs, Visit, &ref_toks)
+ let visit_field = visit(&ty, &v.features, defs, Visit, &ref_toks)
.unwrap_or_else(|| noop_visit(Visit, &ref_toks));
visit_impl.append_all(quote! {
#visit_field;
});
- let visit_mut_field = visit(ty, v.features(), defs, VisitMut, &ref_toks)
+ let visit_mut_field = visit(&ty, &v.features, defs, VisitMut, &ref_toks)
.unwrap_or_else(|| noop_visit(VisitMut, &ref_toks));
visit_mut_impl.append_all(quote! {
#visit_mut_field;
});
- let fold = visit(ty, v.features(), defs, Fold, &ref_toks)
+ let fold = visit(&ty, &v.features, defs, Fold, &ref_toks)
.unwrap_or_else(|| noop_visit(Fold, &ref_toks));
fold_fields.append_all(quote! {
@@ -536,7 +536,7 @@
});
}
- if !v.fields().is_empty() {
+ if !v.fields.is_empty() {
fold_impl.append_all(quote! {
#ty {
#fold_fields
@@ -559,7 +559,7 @@
let mut include_fold_impl = true;
if let types::Node::Struct(ref data) = s {
- if data.fields().is_empty() && !super::TERMINAL_TYPES.contains(&&s.ident()) {
+ if data.fields.is_empty() && !super::TERMINAL_TYPES.contains(&&s.ident()) {
include_fold_impl = false;
}
}
@@ -640,7 +640,7 @@
let mut defs = defs.clone();
for &tt in TERMINAL_TYPES {
- defs.insert(types::Node::Struct(types::Struct::new(
+ defs.types.push(types::Node::Struct(types::Struct::new(
tt.to_string(),
types::Features::default(),
IndexMap::new(),
diff --git a/codegen/src/types.rs b/codegen/src/types.rs
index f6ed520..3cbc0b2 100644
--- a/codegen/src/types.rs
+++ b/codegen/src/types.rs
@@ -18,23 +18,23 @@
#[derive(Debug, Clone, Serialize)]
pub struct Struct {
- ident: String,
- features: Features,
+ pub ident: String,
+ pub features: Features,
#[serde(skip_serializing_if = "IndexMap::is_empty")]
- fields: IndexMap<String, Type>,
+ pub fields: IndexMap<String, Type>,
}
#[derive(Debug, Clone, Serialize)]
pub struct Enum {
- ident: String,
- features: Features,
- variants: Vec<Variant>,
+ pub ident: String,
+ pub features: Features,
+ pub variants: Vec<Variant>,
}
#[derive(Debug, Clone, Serialize)]
pub struct Variant {
- ident: String,
- fields: Vec<Type>,
+ pub ident: String,
+ pub fields: Vec<Type>,
}
#[derive(Debug, Clone, Serialize)]
@@ -67,8 +67,8 @@
#[derive(Debug, Clone, Serialize)]
pub struct Punctuated {
- element: Box<Type>,
- punct: String,
+ pub element: Box<Type>,
+ pub punct: String,
}
#[derive(Debug, Default, Clone, Serialize)]
@@ -76,12 +76,6 @@
any: Vec<String>,
}
-impl Definitions {
- pub fn insert(&mut self, node: Node) {
- self.types.push(node);
- }
-}
-
impl Node {
pub fn ident(&self) -> &str {
match self {
@@ -106,14 +100,6 @@
fields,
}
}
-
- pub fn features(&self) -> &Features {
- &self.features
- }
-
- pub fn fields(&self) -> &IndexMap<String, Type> {
- &self.fields
- }
}
impl Enum {
@@ -124,24 +110,12 @@
variants,
}
}
-
- pub fn variants(&self) -> &[Variant] {
- &self.variants
- }
}
impl Variant {
pub fn new(ident: String, fields: Vec<Type>) -> Variant {
Variant { ident, fields }
}
-
- pub fn ident(&self) -> &str {
- &self.ident
- }
-
- pub fn fields(&self) -> &[Type] {
- &self.fields
- }
}
impl Punctuated {
@@ -151,10 +125,6 @@
punct,
}
}
-
- pub fn element(&self) -> &Type {
- &self.element
- }
}
impl Features {