Skip to content

Commit 3c67fc9

Browse files
committed
docs: add some comments.
1 parent f4bfa9b commit 3c67fc9

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

tasks/ast_codegen/src/generators/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ mod ast_kind;
33
mod count_unvisited;
44
mod impl_get_span;
55

6+
/// Inserts a newline in the `TokenStream`.
7+
#[allow(unused)]
8+
macro_rules! endl {
9+
() => {
10+
/* only works in the context of `quote` macro family! */
11+
};
12+
}
13+
614
/// Similar to how `insert` macro works in the context of `quote` macro family, But this one can be
715
/// used outside and accepts expressions.
816
/// Wraps the result of the given expression in `insert!({value here});` and outputs it as `TokenStream`.

tasks/ast_codegen/src/linker.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ impl<'a> Linker<'a> for CodegenCtx {
3030
&'a self,
3131
mut linker: impl FnMut(&mut RType, &'a Self) -> Result<bool>,
3232
) -> Result<&'a ()> {
33+
// we sort by `TypeId` so we always have the same ordering as how it is written in the rust.
3334
let mut unresolved = self
3435
.ident_table
3536
.iter()
3637
.sorted_by_key(|it| it.1)
3738
.map(|it| it.0)
3839
.collect::<VecDeque<_>>();
40+
3941
while let Some(next) = unresolved.pop_back() {
4042
let next_id = *self.type_id(next).unwrap();
4143

@@ -51,8 +53,7 @@ impl<'a> Linker<'a> for CodegenCtx {
5153
}
5254
}
5355

54-
/// Returns false if can't resolve
55-
/// TODO: right now we don't resolve nested inherits, return is always true for now.
56+
/// Returns false if can't resolve at the moment
5657
/// # Panics
5758
/// On invalid inheritance.
5859
#[allow(clippy::unnecessary_wraps)]

tasks/ast_codegen/src/schema.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,13 @@ impl Module {
220220
})
221221
.map(TryInto::try_into)
222222
.map_ok(|it| Rc::new(RefCell::new(it)))
223-
// .collect::<Vec<RType>>();
224223
.collect::<Result<_>>()?;
225224
self.loaded = true;
226225
Ok(self)
227226
}
228227

228+
/// Expand `inherit_variants` macros to their inner enum.
229+
/// This would also populate `inherits` field of `EnumMeta` types.
229230
pub fn expand(self) -> Result<Self> {
230231
if !self.loaded {
231232
return Err(String::from(LOAD_ERROR));
@@ -235,6 +236,7 @@ impl Module {
235236
Ok(self)
236237
}
237238

239+
/// Fills the Meta types.
238240
pub fn analyze(self) -> Result<Self> {
239241
if !self.loaded {
240242
return Err(String::from(LOAD_ERROR));
@@ -250,6 +252,7 @@ impl Module {
250252
}
251253

252254
let definitions = Definitions {
255+
// We filter map to get rid of stuff we don't need in our schema.
253256
types: self.items.into_iter().filter_map(|it| (&*it.borrow()).into()).collect(),
254257
};
255258
Ok(Schema { source: self.path, definitions })
@@ -262,6 +265,11 @@ pub fn expand(type_def: &TypeRef) -> Result<()> {
262265
let (enum_, inherits) = mac
263266
.mac
264267
.parse_body_with(|input: &ParseBuffer| {
268+
// Because of `@inherit`s we can't use the actual `ItemEnum` parse,
269+
// This closure is similar to how `ItemEnum` parser works, With the exception
270+
// of how we approach our variants, First we try to parse a variant out of our
271+
// tokens if we fail we try parsing the inheritance, And we would raise an
272+
// error only if both of these fail.
265273
let attrs = input.call(Attribute::parse_outer)?;
266274
let vis = input.parse::<Visibility>()?;
267275
let enum_token = input.parse::<Token![enum]>()?;

0 commit comments

Comments
 (0)