]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
libvaladoc: Add support for single line documentation comments
authorMichael James Gratton <mike@vee.net>
Tue, 9 Jan 2018 01:30:50 +0000 (12:30 +1100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Tue, 9 Jan 2018 07:13:08 +0000 (08:13 +0100)
This is useful for example in annotating properties:

   /** Returns the current state of the frobnocator. */
   public State frob { get; set; };

* libvaladoc/documentation/documentationparser.vala
  (DocumentationParser.init_valadoc_rules): Split Comment rule up into
  single and multi-line versions. Duplication Paragraph creation and
  cleanup for single-line comments.

https://bugzilla.gnome.org/show_bug.cgi?id=736483

libvaladoc/documentation/documentationparser.vala

index a03480c7392e372a2b4fdad8013d57997fc6e213..4a9c0c9bdc9b8ac290269e042f82790621c66c57 100644 (file)
@@ -548,6 +548,16 @@ public class Valadoc.DocumentationParser : Object, ResourceLocator {
 
                // Block rules
 
+               Rule.Action reduce_paragraph = () => {
+                       var head = (Paragraph) pop ();
+                       ((BlockContent) peek ()).content.add (head);
+
+                       Text last_element = head.content.last () as Text;
+                       if (last_element != null) {
+                               last_element.content._chomp ();
+                       }
+               };
+
                Rule paragraph =
                        Rule.seq ({
                                Rule.option ({
@@ -563,15 +573,7 @@ public class Valadoc.DocumentationParser : Object, ResourceLocator {
                        })
                        .set_name ("Paragraph")
                        .set_start (() => { push (_factory.create_paragraph ()); })
-                       .set_reduce (() => {
-                               var head = (Paragraph) pop ();
-                               ((BlockContent) peek ()).content.add (head);
-
-                               Text last_element = head.content.last () as Text;
-                               if (last_element != null) {
-                                       last_element.content._chomp ();
-                               }
-                       });
+                       .set_reduce (reduce_paragraph);
 
                Rule warning =
                        Rule.seq ({
@@ -876,7 +878,7 @@ public class Valadoc.DocumentationParser : Object, ResourceLocator {
                                ((Comment) peek ()).taglets.add (head);
                        });
 
-               Rule comment =
+               Rule ml_comment =
                        Rule.seq ({
                                TokenType.EOL,
                                Rule.option ({
@@ -886,6 +888,21 @@ public class Valadoc.DocumentationParser : Object, ResourceLocator {
                                        Rule.many ({ taglet })
                                })
                        })
+                       .set_name ("MultiLineComment");
+
+               Rule sl_comment =
+                       Rule.seq ({
+                               run
+                       })
+                       .set_start (() => { push (_factory.create_paragraph ()); })
+                       .set_reduce (reduce_paragraph)
+                       .set_name ("SingleLineComment");
+
+               Rule comment =
+                       Rule.one_of ({
+                               ml_comment,
+                               sl_comment
+                       })
                        .set_name ("Comment")
                        .set_start (() => { push (_factory.create_comment ()); });