Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions misc/codegen/templates/rust_classes.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ impl {{name}} {
pub fn emit_{{singular_field_name}}(id: trap::Label<Self>{{^is_predicate}}{{#is_repeated}}{{^is_unordered}}, i: usize{{/is_unordered}}{{/is_repeated}}, value: {{base_type}}{{/is_predicate}}, out: &mut trap::Writer) {
out.add_tuple("{{table_name}}", vec![id.into(){{^is_predicate}}{{#is_repeated}}{{^is_unordered}}, i.into(){{/is_unordered}}{{/is_repeated}}, value.into(){{/is_predicate}}]);
}

{{#is_repeated}}
pub fn emit_{{field_name}}(id: trap::Label<Self>, values: impl IntoIterator<Item={{base_type}}>, out: &mut trap::Writer) {
values
.into_iter()
{{^is_unordered}}
.enumerate()
.for_each(|(i, value)| Self::emit_{{singular_field_name}}(id, i, value, out));
{{/is_unordered}}
{{#is_unordered}}
.for_each(|value| Self::emit_{{singular_field_name}}(id, value, out));
{{/is_unordered}}
}
{{/is_repeated}}
{{/detached_fields}}
}
{{/has_detached_fields}}
Expand Down
6 changes: 2 additions & 4 deletions rust/ast-generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ struct ExtractorInfo {
}

fn enum_to_extractor_info(node: &AstEnumSrc) -> Option<ExtractorEnumInfo> {
if node.name == "VariantDef" {
// currently defined but unused
if matches!(node.name.as_str(), "VariantDef" | "Adt") {
// these are not used as types of fields, so we don't need to generate extractors for them
return None;
}
Some(ExtractorEnumInfo {
Expand Down Expand Up @@ -485,8 +485,6 @@ fn main() -> anyhow::Result<()> {
.expect("Failed to parse grammar");
let mut grammar = codegen::grammar::lower(&grammar);

grammar.enums.retain(|x| x.name != "Adt");

let mut super_types: BTreeMap<String, BTreeSet<String>> = BTreeMap::new();
for node in &grammar.enums {
for variant in &node.variants {
Expand Down
2 changes: 1 addition & 1 deletion rust/extractor/src/generated/.generated.list

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading