Skip to content

Commit ca6c054

Browse files
committed
Rust: Rename Adt class and lift common predicates to it
1 parent 22bc924 commit ca6c054

File tree

4 files changed

+34
-11
lines changed

4 files changed

+34
-11
lines changed

rust/ast-generator/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use ungrammar::Grammar;
1515

1616
fn class_name(type_name: &str) -> String {
1717
match type_name {
18+
"Adt" => "TypeItem".to_owned(),
1819
"BinExpr" => "BinaryExpr".to_owned(),
1920
"ElseBranch" => "Expr".to_owned(),
2021
"Fn" => "Function".to_owned(),

rust/extractor/src/translate/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ impl<'a> Translator<'a> {
674674
pub(crate) fn emit_derive_expansion(
675675
&mut self,
676676
node: &(impl Into<ast::Adt> + Clone),
677-
label: impl Into<Label<generated::Adt>> + Copy,
677+
label: impl Into<Label<generated::TypeItem>> + Copy,
678678
) {
679679
let Some(semantics) = self.semantics else {
680680
return;
@@ -686,7 +686,7 @@ impl<'a> Translator<'a> {
686686
.flatten()
687687
.filter_map(|expanded| self.process_item_macro_expansion(&node, expanded))
688688
.collect::<Vec<_>>();
689-
generated::Adt::emit_derive_macro_expansions(
689+
generated::TypeItem::emit_derive_macro_expansions(
690690
label.into(),
691691
expansions,
692692
&mut self.trap.writer,

rust/schema/annotations.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@ class LoopingExpr(LabelableExpr):
1818
loop_body: optional["BlockExpr"] | child
1919

2020

21-
@annotate(Adt, replace_bases={AstNode: Item})
21+
@annotate(TypeItem, replace_bases={AstNode: Item})
2222
class _:
2323
"""
24-
An ADT (Abstract Data Type) definition, such as `Struct`, `Enum`, or `Union`.
24+
An item that defines a type. Either a `Struct`, `Enum`, or `Union`.
2525
"""
2626

2727
derive_macro_expansions: list[MacroItems] | child | rust.detach
28+
attrs: list["Attr"] | child
29+
generic_param_list: optional["GenericParamList"] | child
30+
name: optional["Name"] | child
31+
visibility: optional["Visibility"] | child
32+
where_clause: optional["WhereClause"] | child
2833

2934

3035
@annotate(Module)
@@ -1063,7 +1068,7 @@ class _:
10631068
"""
10641069

10651070

1066-
@annotate(Enum, replace_bases={Item: None}) # still an Item via Adt
1071+
@annotate(Enum, replace_bases={Item: None})
10671072
class _:
10681073
"""
10691074
An enum declaration.
@@ -1074,6 +1079,12 @@ class _:
10741079
```
10751080
"""
10761081

1082+
attrs: drop
1083+
generic_param_list: drop
1084+
name: drop
1085+
visibility: drop
1086+
where_clause: drop
1087+
10771088

10781089
@annotate(ExternBlock)
10791090
class _:
@@ -1893,7 +1904,7 @@ class _:
18931904
)
18941905

18951906

1896-
@annotate(Struct, replace_bases={Item: None}) # still an Item via Adt
1907+
@annotate(Struct, replace_bases={Item: None})
18971908
class _:
18981909
"""
18991910
A Struct. For example:
@@ -1906,6 +1917,11 @@ class _:
19061917
"""
19071918

19081919
field_list: _ | ql.db_table_name("struct_field_lists_")
1920+
attrs: drop
1921+
generic_param_list: drop
1922+
name: drop
1923+
visibility: drop
1924+
where_clause: drop
19091925

19101926

19111927
@annotate(TokenTree)
@@ -2075,7 +2091,7 @@ class _:
20752091
"""
20762092

20772093

2078-
@annotate(Union, replace_bases={Item: None}) # still an Item via Adt
2094+
@annotate(Union, replace_bases={Item: None})
20792095
class _:
20802096
"""
20812097
A union declaration.
@@ -2086,6 +2102,12 @@ class _:
20862102
```
20872103
"""
20882104

2105+
attrs: drop
2106+
generic_param_list: drop
2107+
name: drop
2108+
visibility: drop
2109+
where_clause: drop
2110+
20892111

20902112
@annotate(Use)
20912113
class _:

rust/schema/ast.py

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)