Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not generate empty docstring for Rule #987

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Changes from all 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
50 changes: 46 additions & 4 deletions generator/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,17 @@ fn generate_enum(
});

let grammar_doc = &doc_comment.grammar_doc;
let mut result = quote! {
#[doc = #grammar_doc]
#[allow(dead_code, non_camel_case_types, clippy::upper_case_acronyms)]
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
let mut result = if grammar_doc.is_empty() {
quote! {
#[allow(dead_code, non_camel_case_types, clippy::upper_case_acronyms)]
sunng87 marked this conversation as resolved.
Show resolved Hide resolved
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
}
} else {
quote! {
#[doc = #grammar_doc]
#[allow(dead_code, non_camel_case_types, clippy::upper_case_acronyms)]
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
}
};
if non_exhaustive {
result.append_all(quote! {
Expand Down Expand Up @@ -865,6 +872,41 @@ mod tests {
);
}

#[test]
fn rule_empty_doc() {
let rules = vec![OptimizedRule {
name: "f".to_owned(),
ty: RuleType::Normal,
expr: OptimizedExpr::Ident("g".to_owned()),
}];

let mut line_docs = HashMap::new();
line_docs.insert("f".to_owned(), "This is rule comment".to_owned());

let doc_comment = &DocComment {
grammar_doc: "".to_owned(),
line_docs,
};

assert_eq!(
generate_enum(&rules, doc_comment, false, false).to_string(),
quote! {
#[allow(dead_code, non_camel_case_types, clippy::upper_case_acronyms)]
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum Rule {
#[doc = "This is rule comment"]
r#f
}
impl Rule {
pub fn all_rules() -> &'static [Rule] {
&[Rule::r#f]
}
}
}
.to_string()
);
}

#[test]
fn sequence() {
let expr = OptimizedExpr::Seq(
Expand Down
Loading