Repository: pest-parser/pest (language: rust)

Issue:
Line doc "already defined" error
If we define line comment has multiple same contents, then will get compile error.

```rust
/// Matches dar
/// 
/// Match dar description
/// 
dar = { "da" }
```

This line doc has 2 empty lines, then will error:

```
thread 'tests::test_generate_doc' panicked at 'grammar error

  --> 19:1
   |
19 | ///
   | ^--^
   |
   = rule ///  already defined', /Users/jason/github/pest/meta/src/lib.rs:42:9
```


Discussion / hints:

Fix patch:
diff --git a/generator/src/docs.rs b/generator/src/docs.rs
index 8660e538..f1ce1881 100644
--- a/generator/src/docs.rs
+++ b/generator/src/docs.rs
@@ -106,16 +106,16 @@ mod tests {
         expected.insert("foo".to_owned(), "Matches foo str, e.g.: `foo`".to_owned());
         expected.insert(
             "bar".to_owned(),
-            "Matches bar str,\n  Indent 2, e.g: `bar` or `foobar`".to_owned(),
+            "Matches bar str\n\n  Indent 2, e.g: `bar` or `foobar`".to_owned(),
         );
         expected.insert(
             "dar".to_owned(),
-            "Matches dar\nMatch dar description".to_owned(),
+            "Matches dar\n\nMatch dar description\n".to_owned(),
         );
         assert_eq!(expected, doc_comment.line_docs);
 
         assert_eq!(
-            "A parser for JSON file.\nAnd this is a example for JSON parser.\n\n    indent-4-space",
+            "A parser for JSON file.\nAnd this is a example for JSON parser.\n\n    indent-4-space\n",
             doc_comment.grammar_doc
         );
     }
diff --git a/generator/src/lib.rs b/generator/src/lib.rs
index f9c118f8..f8089878 100644
--- a/generator/src/lib.rs
+++ b/generator/src/lib.rs
@@ -236,6 +236,7 @@ mod tests {
         parse_derive(ast);
     }
 
+    #[doc = "Matches dar\n\nMatch dar description\n"]
     #[test]
     fn test_generate_doc() {
         let input = quote! {
@@ -247,17 +248,17 @@ mod tests {
         let token = super::derive_parser(input, true);
 
         let expected = quote! {
-            #[doc = "A parser for JSON file.\nAnd this is a example for JSON parser.\n\n    indent-4-space"]
+            #[doc = "A parser for JSON file.\nAnd this is a example for JSON parser.\n\n    indent-4-space\n"]
             #[allow(dead_code, non_camel_case_types, clippy::upper_case_acronyms)]
             #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
 
             pub enum Rule {
                 #[doc = "Matches foo str, e.g.: `foo`"]
                 r#foo,
-                #[doc = "Matches bar str,\n  Indent 2, e.g: `bar` or `foobar`"]
+                #[doc = "Matches bar str\n\n  Indent 2, e.g: `bar` or `foobar`"]
                 r#bar,
                 r#bar1,
-                #[doc = "Matches dar\nMatch dar description"]
+                #[doc = "Matches dar\n\nMatch dar description\n"]
                 r#dar
             }
         };
diff --git a/meta/src/validator.rs b/meta/src/validator.rs
index cfc445f0..d9c2ed3c 100644
--- a/meta/src/validator.rs
+++ b/meta/src/validator.rs
@@ -81,7 +81,9 @@ pub fn validate_pairs(pairs: Pairs<'_, Rule>) -> Result<Vec<&str>, Vec<Error<Rul
     let definitions: Vec<_> = pairs
         .clone()
         .filter(|pair| pair.as_rule() == Rule::grammar_rule)
-        .map(|pair| pair.into_inner().next().unwrap().as_span())
+        .map(|pair| pair.into_inner().next().unwrap())
+        .filter(|pair| pair.as_rule() != Rule::line_doc)
+        .map(|pair| pair.as_span())
         .collect();
 
     let called_rules: Vec<_> = pairs


Test patch:
diff --git a/generator/tests/test.pest b/generator/tests/test.pest
index c86a65ff..95d484e9 100644
--- a/generator/tests/test.pest
+++ b/generator/tests/test.pest
@@ -2,11 +2,13 @@
 //! And this is a example for JSON parser.
 //!
 //!     indent-4-space
+//!
 
 /// Matches foo str, e.g.: `foo`
 foo = { "foo" }
 
-/// Matches bar str,
+/// Matches bar str
+///
 ///   Indent 2, e.g: `bar` or `foobar`
 
 bar = { "bar" | "foobar" }
@@ -14,7 +16,8 @@ bar = { "bar" | "foobar" }
 bar1 = { "bar1" }
 
 /// Matches dar
-
+/// 
 /// Match dar description
+/// 
 
 dar = { "da" }
\ No newline at end of file