Closed matklad closed 5 years ago
I guess it will be difficult to design a model suited for quote!
and template engines like tera
equally good. I still hope to keep asdl available for other languages and templates will be preferable for it.
I suggest to keep two models in this case. One current with some changes and one as you said. In separate crates ofcourse.
By the way, the new rust-analizer codegen is really impressive. Didn't know that you can do such tricks in rust.
Made commit with suggested changes. f3f2e38167b80ffbe3fded047426288833eae79e Old model was moved to the asdl_tera crate. New model placed in main asdl crate.
I guess it will be difficult to design a model suited for quote! and template engines like tera equally good.
I think the solution here is to have a dead-simple core model, which is not specific to any code-gen solution, and is concerned with pure ASDL. Various codegen backends can then decorate the core model with something required for an engine.
I guess it will be difficult to design a model suited for quote! and template engines like tera equally good.
I think the solution here is to have a dead-simple core model, which is not specific to any code-gen solution, and is concerned with pure ASDL. Various codegen backends can then decorate the core model with something required for an engine.
Agree. Your suggested model is implemented here.
model::ASDL
should provide public API, and not only serialization API. In the new rust-analyzer codegen, we don't make use of serialization at allperhaps it makes sense to keep things simple, define
Asdl
aspub struct Asdl { pub types: Vec<Type> }
and provides accessors likeimpl Asdl { fn get_type_by_name(&self, name: &str) -> Option<Type>}
. We shouldn't worry about performance, linear scan should be okremove
is_prod_type
: static type of the node has this information, no need to track it at runtime.instead of a bunch of
bool
fields, aField
should havearity: Arity
, whereArity
is defined asenum Arity { Optional, Required, Repeated }
code organization wise, it might be useful to separate into different files public API for reading the model, from the private API for constructig the model our of AST. It's possible to have impl blocks for a struct in a file, different from the one where the said struct is defined.