]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
libvaladoc: Accept block content in list-items
authorFlorian Brosch <flo.brosch@gmail.com>
Sun, 29 Jan 2012 17:49:40 +0000 (18:49 +0100)
committerFlorian Brosch <flo.brosch@gmail.com>
Sun, 29 Jan 2012 19:06:06 +0000 (20:06 +0100)
src/libvaladoc/content/listitem.vala
src/libvaladoc/documentation/documentationparser.vala
src/libvaladoc/documentation/gtkdoccommentparser.vala
src/libvaladoc/html/htmlrenderer.vala

index ef5f589f7c66f8ff12f7bc82101f67e0c12aa9d6..98104b767b4ed88924af35b0a487f6a8797f7046 100755 (executable)
 using Gee;
 
 
-public class Valadoc.Content.ListItem : InlineContent {
-       public List? sub_list { get; set; }
+public class Valadoc.Content.ListItem : BlockContent {
 
        internal ListItem () {
                base ();
        }
 
        public override void check (Api.Tree api_root, Api.Node container, string file_path, ErrorReporter reporter, Settings settings) {
-               // Check inline content
+               // Check block content
                base.check (api_root, container, file_path, reporter, settings);
-
-               if (sub_list != null) {
-                       sub_list.check (api_root, container, file_path, reporter, settings);
-               }
        }
 
        public override void accept (ContentVisitor visitor) {
@@ -46,9 +41,5 @@ public class Valadoc.Content.ListItem : InlineContent {
 
        public override void accept_children (ContentVisitor visitor) {
                base.accept_children (visitor);
-
-               if (sub_list != null) {
-                       sub_list.accept (visitor);
-               }
        }
 }
index 5fa736a5a6096c46bf09f42a78d8d326a0775467..bf79166d0884d417f14ec436a21fac1a1312927e 100755 (executable)
@@ -145,15 +145,20 @@ public class Valadoc.DocumentationParser : Object, ResourceLocator {
 
        private void new_list_item (Content.List.Bullet bullet) throws ParserError {
                var new_item = _factory.create_list_item ();
+               var content = _factory.create_paragraph ();
+               new_item.content.add (content);
 
                Content.List list = null;
                if (levels.length >= 1) {
+                       // Pop current content
+                       pop ();
+
                        if (current_level > levels[levels.length - 1]) {
                                list = _factory.create_list ();
                                list.bullet = bullet;
 
                                var current_item = peek () as ListItem;
-                               current_item.sub_list = list;
+                               current_item.content.add (list);
                                push (list);
 
                                levels += current_level;
@@ -191,6 +196,7 @@ public class Valadoc.DocumentationParser : Object, ResourceLocator {
 
                list.items.add (new_item);
                push (new_item);
+               push (content);
        }
 
        private string bullet_type_string (Content.List.Bullet bullet) {
@@ -214,6 +220,9 @@ public class Valadoc.DocumentationParser : Object, ResourceLocator {
        }
 
        private void finish_list () {
+               // pop content
+               pop ();
+
                while (peek () is ListItem) {
                        pop ();
                        pop ();
@@ -569,7 +578,7 @@ public class Valadoc.DocumentationParser : Object, ResourceLocator {
                        .set_name ("IndentedItem")
                        .set_start (() => { current_level = 0; })
                        .set_reduce (() => {
-                               var content_list = ((ListItem) peek ()).content;
+                               var content_list = ((InlineContent) peek ()).content;
                                if (content_list.size > 0 && content_list.last () is Text) {
                                        ((Text) content_list.last ()).content._chomp ();
                                }
@@ -795,8 +804,8 @@ public class Valadoc.DocumentationParser : Object, ResourceLocator {
        }
 
 #if DEBUG
-       private void dump_stack () {
-               message ("Dumping stack");
+       private void dump_stack (string title) {
+               message ("=== Dumping stack: %s ===", title);
                foreach (Object object in _stack) {
                        message ("%s", object.get_type ().name ());
                }
index f3718ceddb4e8abb6fbfe8c65784197fb50300d5..a437a663be18b7eb587c221c9db3dbd5220a18a8 100644 (file)
@@ -549,27 +549,7 @@ public class Valadoc.Gtkdoc.Parser : Object, ResourceLocator {
                ListItem item = factory.create_list_item ();
        
                while (current.type != TokenType.XML_CLOSE && current.type != TokenType.EOF) {
-                       if (current.type == TokenType.XML_OPEN && current.content == "para") {
-                               foreach (Block block in parse_docbook_para ()) {
-                                       if (block is Paragraph) {
-                                               if (item.content.size > 0) {
-                                                       item.content.add (factory.create_text ("\n"));
-                                               }
-
-                                               item.content.add_all (((Paragraph) block).content);
-                                       } else {
-                                               // TODO: extend me
-                                               this.report_unexpected_token (current, "<para>|</listitem>");
-                                               return null;
-                                       }
-                               }
-                       } else {
-                               Token tmp_t = current;
-                               parse_inline_content ();
-                               if (tmp_t == current) {
-                                       break;
-                               }
-                       }
+                       item.content.add_all (parse_mixed_content ());
                }
 
                if (!check_xml_close_tag ("listitem")) {
@@ -693,7 +673,7 @@ public class Valadoc.Gtkdoc.Parser : Object, ResourceLocator {
                        }
 
                        LinkedList<Block> lst = parse_block_content ();
-                       if (lst != null && run.content.size > 0) {
+                       if (lst != null && lst.size > 0) {
                                content.add_all (lst);
                                continue;
                        }
@@ -702,9 +682,13 @@ public class Valadoc.Gtkdoc.Parser : Object, ResourceLocator {
                return content;
        }
 
-       private LinkedList<Block>? parse_docbook_para () {
-               if (!check_xml_open_tag ("para")) {
-                       this.report_unexpected_token (current, "<para>");
+       private inline LinkedList<Block>? parse_docbook_simpara () {
+               return parse_docbook_para ("simpara");
+       }
+
+       private LinkedList<Block>? parse_docbook_para (string tag_name = "para") {
+               if (!check_xml_open_tag (tag_name)) {
+                       this.report_unexpected_token (current, "<%s>".printf (tag_name));
                        return null;
                }
 
@@ -712,8 +696,9 @@ public class Valadoc.Gtkdoc.Parser : Object, ResourceLocator {
 
                LinkedList<Block> content = parse_mixed_content ();
 
-               if (!check_xml_close_tag ("para")) {
-                       this.report_unexpected_token (current, "</para>");
+               // ignore missing </para> to match gtkdocs behaviour
+               if (!check_xml_close_tag (tag_name) && current.type != TokenType.EOF) {
+                       this.report_unexpected_token (current, "</%s>".printf (tag_name));
                        return content;
                }
 
@@ -1225,6 +1210,8 @@ public class Valadoc.Gtkdoc.Parser : Object, ResourceLocator {
                                this.append_block_content_not_null (content, parse_docbook_programlisting ());
                        } else if (current.type == TokenType.XML_OPEN && current.content == "para") {
                                this.append_block_content_not_null_all (content, parse_docbook_para ());
+                       } else if (current.type == TokenType.XML_OPEN && current.content == "simpara") {
+                               this.append_block_content_not_null_all (content, parse_docbook_simpara ());
                        } else if (current.type == TokenType.XML_OPEN && current.content == "informalexample") {
                                this.append_block_content_not_null_all (content, parse_docbook_informalexample ());
                        } else if (current.type == TokenType.XML_OPEN && current.content == "example") {
index 153e844b96f43d6d8ce8a46c7571168c94a8f0e8..4bf69d7427b74bee4920ef6192cca5424155bd6f 100755 (executable)
@@ -355,7 +355,20 @@ public class Valadoc.Html.HtmlRenderer : ContentRenderer {
 
        public override void visit_list_item (ListItem element) {
                writer.start_tag ("li");
-               element.accept_children (this);
+               Paragraph? first_para = (element.content.size > 0)? element.content[0] as Paragraph : null;
+               if (first_para != null) {
+                       // We do not pick up alignments in gir-files.
+                       first_para.accept_children (this);
+                       bool first_entry = true;
+                       foreach (var item in element.content) {
+                               if (!first_entry) {
+                                       item.accept (this);
+                               }
+                               first_entry = false;
+                       }
+               } else {
+                       element.accept_children (this);
+               }
                writer.end_tag ("li");
        }