core: fix typos in doc of CircularArray
[nit.git] / src / doc / doc_phases / doc_readme.nit
index c026b77..b7d2ac8 100644 (file)
@@ -38,7 +38,8 @@ class ReadmePhase
        fun warning(location: nullable MDLocation, page: ReadmePage, message: String) do
                var loc = null
                if location != null then
-                       loc = location.to_location(page.mentity.mdoc.location.file)
+                       var mdoc = page.mentity.mdoc
+                       if mdoc != null then loc = location.to_location(mdoc.location.file)
                end
                ctx.warning(loc, "readme-warning", message)
        end
@@ -51,21 +52,21 @@ end
 
 redef class ReadmePage
        redef fun build_content(v, doc) do
-               if mentity.mdoc == null then
+               var mdoc = mentity.mdoc
+               if mdoc == null then
                        v.warning(null, self, "Empty README for group `{mentity}`")
                        return
                end
-               var proc = new MarkdownProcessor
-               proc.emitter = new ReadmeMdEmitter(proc, self, v)
-               proc.emitter.decorator = new ReadmeDecorator
-               var md = mentity.mdoc.content.join("\n")
+               var proc = new ReadmeMdProcessor(self, v)
+               proc.decorator = new ReadmeDecorator
+               var md = mdoc.content.join("\n")
                proc.process(md)
        end
 end
 
 # Markdown emitter used to produce the `ReadmeArticle`.
-class ReadmeMdEmitter
-       super MarkdownEmitter
+class ReadmeMdProcessor
+       super MarkdownProcessor
 
        # Readme page being decorated.
        var page: ReadmePage
@@ -90,7 +91,8 @@ class ReadmeMdEmitter
        #
        # Called from `add_headline`.
        private fun open_section(lvl: Int, title: String) do
-               var section = new ReadmeSection(title.escape_to_c, title, lvl, processor)
+               var section = new ReadmeSection(title.escape_to_c, title, lvl, self)
+               var current_section = self.current_section
                if current_section == null then
                        page.root.add_child(section)
                else
@@ -119,6 +121,7 @@ class ReadmeMdEmitter
        # This closes the current article, inserts `article` then opens a new article.
        private fun add_article(article: DocArticle) do
                close_article
+               var current_section = self.current_section
                if current_section == null then
                        page.root.add_child(article)
                else
@@ -133,7 +136,7 @@ class ReadmeMdEmitter
        private fun open_article do
                var section: DocComposite = page.root
                if current_section != null then section = current_section.as(not null)
-               var article = new ReadmeArticle("mdarticle-{section.children.length}", null, processor)
+               var article = new ReadmeArticle("mdarticle-{section.children.length}", null, self)
                section.add_child(article)
                context.add article
                push_article article
@@ -184,15 +187,18 @@ end
 class ReadmeDecorator
        super MdDecorator
 
-       redef type EMITTER: ReadmeMdEmitter
+       # Parser used to process doc commands
+       var parser = new DocCommandParser
+
+       redef type PROCESSOR: ReadmeMdProcessor
 
        redef fun add_headline(v, block) do
-               var txt = block.block.first_line.value
+               var txt = block.block.first_line.as(not null).value
                var lvl = block.depth
                if not v.context.is_empty then
                        v.close_article
                        while v.current_section != null do
-                               if v.current_section.depth < lvl then break
+                               if v.current_section.as(not null).depth < lvl then break
                                v.close_section
                        end
                end
@@ -201,9 +207,9 @@ class ReadmeDecorator
        end
 
        redef fun add_wikilink(v, token) do
-               var link = token.link.to_s
-               var cmd = new DocCommand(link)
-               if cmd isa UnknownCommand then
+               var link = token.link.as(not null).to_s
+               var cmd = parser.parse(link)
+               if cmd == null then
                        # search MEntities by name
                        var res = v.find_mentities(link.to_s)
                        # no match, print warning and display wikilink as is
@@ -219,24 +225,25 @@ class ReadmeDecorator
        end
 
        # Renders a link to a mentity.
-       private fun add_mentity_link(v: EMITTER, mentity: MEntity, name, comment: nullable Text) do
+       private fun add_mentity_link(v: PROCESSOR, mentity: MEntity, name, comment: nullable Text) do
                # TODO real link
                var link = mentity.full_name
                if name == null then name = mentity.name
-               if comment == null and mentity.mdoc != null then
-                       comment = mentity.mdoc.synopsis
+               if comment == null then
+                       var mdoc = mentity.mdoc
+                       if mdoc != null then comment = mdoc.synopsis
                end
                add_link(v, link, name, comment)
        end
 end
 
-redef interface DocCommand
+redef class DocCommand
 
        # Render the content of the doc command.
-       fun render(v: ReadmeMdEmitter, token: TokenWikiLink) is abstract
+       fun render(v: ReadmeMdProcessor, token: TokenWikiLink) is abstract
 end
 
-redef class ArticleCommand
+redef class CommentCommand
        redef fun render(v, token) do
                var string = args.first
                var res = v.find_mentities(string)
@@ -267,7 +274,7 @@ redef class ListCommand
                if mentity isa MModule then
                        v.add_article new MEntitiesListArticle("Classes", null, mentity.mclassdefs)
                else if mentity isa MClass then
-                       var mprops = mentity.collect_intro_mproperties(mentity.public_view)
+                       var mprops = mentity.collect_intro_mproperties(v.phase.doc)
                        v.add_article new MEntitiesListArticle("Methods", null, mprops.to_a)
                else if mentity isa MClassDef then
                        v.add_article new MEntitiesListArticle("Methods", null, mentity.mpropdefs)