+end
+
+
+# A generic information container that can be used to decorate AST entities
+class HInfoBox
+ # The visitor used for contextualisation, if needed
+ var visitor: HighlightVisitor
+
+ # A short title for the AST element
+ var title: String
+
+ # The primary link where the entity points
+ # null if no link
+ var href: nullable String = null
+
+ # The content of the popuped infobox
+ var content = new HTMLTag("div")
+
+ # Append a new field in the popuped infobox
+ fun new_field(title: String): HTMLTag
+ do
+ content.open("b").text(title)
+ content.append(" ")
+ var res = content.open("span")
+ content.open("br")
+ return res
+ end
+
+ # Append a new dropdown in the popuped content
+ fun new_dropdown(title, text: String): HTMLTag
+ do
+ content.add_raw_html """<div class="dropdown"> <a data-toggle="dropdown" href="#"><b>"""
+ content.append(title)
+ content.add_raw_html "</b> "
+ content.append(text)
+ content.add_raw_html """<span class="caret"></span></a>"""
+ var res = content.open("ul").add_class("dropdown-menu").attr("role", "menu").attr("aria-labelledby", "dLabel")
+ content.add_raw_html "</div>"
+ return res
+ end
+end
+
+##
+
+# Model entity or whatever that can produce an infobox
+interface HInfoBoxable
+ # An new infobox documenting the entity
+ fun infobox(v: HighlightVisitor): HInfoBox is abstract
+
+ # A human-readable hyper-text for the entity
+ fun linkto: HTMLTag is abstract
+end
+
+redef class MDoc
+ # Append an entry for the doc in the given infobox
+ fun fill_infobox(res: HInfoBox)
+ do
+ if content.length < 2 then
+ res.new_field("doc").text(content.first)
+ return
+ end
+ var c = res.new_dropdown("doc", content.first)
+ for x in content.iterator.skip_head(1) do
+ c.append x
+ c.add_raw_html "<br>"
+ end
+ end
+end
+
+redef class MEntity
+ super HInfoBoxable
+end
+
+redef class MModule
+ redef fun infobox(v)
+ do
+ var res = new HInfoBox(v, "module {name}")
+ res.href = href
+ res.new_field("module").add(linkto)
+ var mdoc = self.mdoc
+ if mdoc != null then mdoc.fill_infobox(res)
+ if in_importation.greaters.length > 1 then
+ var c = res.new_dropdown("imports", "{in_importation.greaters.length-1} modules")
+ for x in in_importation.greaters do
+ if x == self then continue
+ c.open("li").add x.linkto
+ end
+ end
+ return res
+ end
+
+ fun href: String
+ do
+ return name + ".html"
+ end
+
+ redef fun linkto do return linkto_text(name)
+
+ # Link to the entitiy with a specific text
+ fun linkto_text(text: String): HTMLTag
+ do
+ return (new HTMLTag("a")).attr("href", href).text(text)
+ end
+end
+
+redef class MClassDef
+ redef fun infobox(v)
+ do
+ var res = new HInfoBox(v, "class {mclass.name}")
+ res.href = href
+ if is_intro then
+ res.new_field("class").text(mclass.name)
+ else
+ res.new_field("redef class").text(mclass.name)
+ res.new_field("intro").add mclass.intro.linkto_text("in {mclass.intro.mmodule.to_s}")
+ end
+ var mdoc = self.mdoc
+ if mdoc == null then mdoc = mclass.intro.mdoc
+ if mdoc != null then mdoc.fill_infobox(res)
+
+ if in_hierarchy.greaters.length > 1 then
+ var c = res.new_dropdown("hier", "super-classes")
+ for x in in_hierarchy.greaters do
+ if x == self then continue
+ if not x.is_intro then continue
+ c.open("li").add x.linkto
+ end
+ end
+ if in_hierarchy.smallers.length > 1 then
+ var c = res.new_dropdown("hier", "sub-classes")
+ for x in in_hierarchy.smallers do
+ if x == self then continue
+ if not x.is_intro then continue
+ c.open("li").add x.linkto
+ end
+ end
+ if mclass.mclassdefs.length > 1 then
+ var c = res.new_dropdown("redefs", "refinements")
+ for x in mclass.mclassdefs do
+ if x == self then continue
+ c.open("li").add x.linkto_text("in {x.mmodule}")
+ end
+ end
+ return res
+ end
+
+ fun href: String
+ do
+ return mmodule.href + "#" + to_s
+ end
+
+ redef fun linkto do return linkto_text(mclass.name)
+
+ # Link to the entitiy with a specific text
+ fun linkto_text(text: String): HTMLTag
+ do
+ return (new HTMLTag("a")).attr("href", href).text(text)
+ end
+end
+
+redef class MPropDef
+ redef fun infobox(v)
+ do
+ var res = new HInfoBox(v, to_s)
+ res.href = href
+ if self isa MMethodDef then
+ res.new_field("fun").append(mproperty.name).add msignature.linkto
+ else if self isa MAttributeDef then
+ res.new_field("fun").append(mproperty.name).add static_mtype.linkto
+ else if self isa MVirtualTypeDef then
+ res.new_field("add").append(mproperty.name).add bound.linkto
+ else
+ res.new_field("wat?").append(mproperty.name)
+ end
+
+ if is_intro then
+ else
+ res.new_field("intro").add mproperty.intro.linkto_text("in {mproperty.intro.mclassdef}")
+ end
+ var mdoc = self.mdoc
+ if mdoc == null then mdoc = mproperty.intro.mdoc
+ if mdoc != null then mdoc.fill_infobox(res)
+ if mproperty.mpropdefs.length > 1 then
+ var c = res.new_dropdown("redef", "redefinitions")
+ for x in mproperty.mpropdefs do
+ c.open("li").add x.linkto_text("in {x.mclassdef}")
+ end
+ end
+
+ return res
+ end
+
+ fun href: String
+ do
+ return self.mclassdef.mmodule.href + "#" + self.to_s
+ end
+
+ redef fun linkto do return linkto_text(mproperty.name)
+
+ # Link to the entitiy with a specific text
+ fun linkto_text(text: String): HTMLTag
+ do
+ return (new HTMLTag("a")).attr("href", href).text(text)
+ end
+end
+
+redef class MClassType
+ redef fun infobox(v)
+ do
+ var res = new HInfoBox(v, to_s)
+ res.href = mclass.intro.href
+ res.new_field("class").add mclass.intro.linkto
+ var mdoc = mclass.mdoc
+ if mdoc == null then mdoc = mclass.intro.mdoc
+ if mdoc != null then mdoc.fill_infobox(res)
+ return res
+ end
+ redef fun linkto
+ do
+ return mclass.intro.linkto
+ end
+end
+redef class MVirtualType
+ redef fun infobox(v)
+ do
+ var res = new HInfoBox(v, to_s)
+ res.href = mproperty.intro.href
+ var p = mproperty
+ var pd = p.intro
+ res.new_field("virtual type").add pd.linkto
+ var mdoc = pd.mdoc
+ if mdoc != null then mdoc.fill_infobox(res)
+ return res
+ end
+ redef fun linkto
+ do
+ return mproperty.intro.linkto
+ end
+end
+redef class MParameterType
+ redef fun infobox(v)
+ do
+ var res = new HInfoBox(v, to_s)
+ var name = mclass.intro.parameter_names[rank]
+ res.new_field("parameter type").append("{name} from class ").add mclass.intro.linkto
+ return res
+ end
+ redef fun linkto
+ do
+ var name = mclass.intro.parameter_names[rank]
+ return (new HTMLTag("span")).text(name)
+ end
+end
+
+redef class MNullableType
+ redef fun infobox(v)
+ do
+ return mtype.infobox(v)
+ end
+ redef fun linkto
+ do
+ var res = new HTMLTag("span")
+ res.append("nullable ").add(mtype.linkto)
+ return res
+ end
+end
+
+redef class MSignature
+ redef fun linkto
+ do
+ var res = new HTMLTag("span")
+ var first = true
+ if not mparameters.is_empty then
+ res.append "("
+ for p in mparameters do
+ if first then
+ first = false
+ else
+ res.append ", "
+ end
+ res.append p.name
+ res.append ": "
+ res.add p.mtype.linkto
+ end
+ res.append ")"
+ end
+ var ret = return_mtype
+ if ret != null then
+ res.append ": "
+ res.add ret.linkto
+ end
+ return res
+ end
+end
+
+redef class CallSite
+ super HInfoBoxable
+ redef fun infobox(v)
+ do
+ var res = new HInfoBox(v, "call {mpropdef}")
+ res.href = mpropdef.href
+ res.new_field("call").add(mpropdef.linkto).add(msignature.linkto)
+ if mpropdef.is_intro then
+ else
+ res.new_field("intro").add mproperty.intro.linkto_text("in {mproperty.intro.mclassdef}")
+ end
+ var mdoc = mpropdef.mdoc
+ if mdoc == null then mdoc = mproperty.intro.mdoc
+ if mdoc != null then mdoc.fill_infobox(res)
+
+ return res
+ end
+ redef fun linkto
+ do
+ return mpropdef.linkto
+ end
+end
+
+redef class Variable
+ super HInfoBoxable
+ redef fun infobox(v)
+ do
+ if declared_type == null then
+ var res = new HInfoBox(v, "{name}")
+ res.new_field("local var").append("{name}")
+ return res
+ end
+ var res = new HInfoBox(v, "{name}: {declared_type}")
+ res.new_field("local var").append("{name}:").add(declared_type.linkto)
+ return res
+ end
+ redef fun linkto
+ do
+ return (new HTMLTag("span")).text(name)
+ end
+end
+
+
+##
+
+redef class ANode
+ # Optionally creates a tag that encapsulate the AST element on HTML rendering
+ protected fun make_tag(v: HighlightVisitor): nullable HTMLTag do return null
+
+ # Add aditionnal information on a child-token and return an additionnal HInfoBox on it
+ protected fun decorate_tag(v: HighlightVisitor, res: HTMLTag, token: Token): nullable HInfoBox