csv: Move the library to its own directory.
[nit.git] / src / highlight.nit
index fbe013e..5e3acf1 100644 (file)
@@ -15,7 +15,6 @@
 # Highliting of Nit AST
 module highlight
 
-import modelize_property
 import frontend
 import html
 import pipeline
@@ -28,13 +27,13 @@ class HighlightVisitor
 
        # Is the HTML include a nested `<span class"{type_of_node}">` element for each `ANode` of the AST?
        # Used to have a really huge and verbose HTML (mainly for debug)
-       var with_ast writable = false
+       var with_ast = false is writable
 
        # The first line to generate, null if start at the first line
-       var first_line: nullable Int writable = null
+       var first_line: nullable Int = null is writable
 
        # The last line to generate, null if finish at the last line
-       var last_line: nullable Int writable = null
+       var last_line: nullable Int = null is writable
 
        init
        do
@@ -53,7 +52,6 @@ class HighlightVisitor
        do
                var stack2 = new Array[HTMLTag]
                var stack = new Array[Prod]
-               var closes = new Array[Prod]
                var line = 0
                var c: nullable Token = first_token
                var hv = new HighlightVisitor
@@ -167,9 +165,9 @@ class HighlightVisitor
                return """
 .nitcode a { color: inherit; cursor:pointer; }
 .nitcode .popupable:hover { text-decoration: underline; cursor:help; } /* underline titles */
-pre.nitcode .foldable { display: block } /* for block productions*/
-pre.nitcode .line{ display: block } /* for lines */
-pre.nitcode .line:hover{ background-color: #FFFFE0; } /* current line */
+.nitcode .foldable { display: block } /* for block productions*/
+.nitcode .line{ display: block } /* for lines */
+.nitcode .line:hover{ background-color: #FFFFE0; } /* current line */
 .nitcode :target { background-color: #FFF3C2 } /* target highlight*/
 /* lexical raw tokens. independent of usage or semantic: */
 .nitcode .nc_c { color: gray; font-style: italic; } /* comment */
@@ -200,6 +198,22 @@ pre.nitcode .line:hover{ background-color: #FFFFE0; } /* current line */
 .popover { max-width: 800px !important; }
 """
        end
+
+       # Additional content to inject in the <head> tag
+       # Note: does not include `css_content`; handle it yourself.
+       fun head_content: String
+       do
+               return """<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">\n"""
+       end
+
+       # Additional content to inject just before the closing </body> tag
+       fun foot_content: String
+       do
+               return """
+<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
+<script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
+<script>$(".popupable").popover({html:true, placement:'top'})/*initialize bootstrap popover*/</script>"""
+       end
 end
 
 redef class HTMLTag
@@ -335,6 +349,8 @@ redef class MClassDef
                if mdoc == null then mdoc = mclass.intro.mdoc
                if mdoc != null then mdoc.fill_infobox(res)
 
+               if in_hierarchy == null then return res
+
                if in_hierarchy.greaters.length > 1 then
                        var c = res.new_dropdown("hier", "super-classes")
                        for x in in_hierarchy.greaters do
@@ -381,11 +397,11 @@ redef class MPropDef
                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
+                       if msignature != null 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
+                       if static_mtype != null 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
+                       if bound != null then res.new_field("add").append(mproperty.name).add bound.linkto
                else
                        res.new_field("wat?").append(mproperty.name)
                end
@@ -458,13 +474,11 @@ 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
@@ -537,6 +551,7 @@ redef class Variable
        super HInfoBoxable
        redef fun infobox(v)
        do
+               var declared_type = self.declared_type
                if declared_type == null then
                        var res = new HInfoBox(v, "{name}")
                        res.new_field("local var").append("{name}")
@@ -650,9 +665,9 @@ end
 redef class AVarFormExpr
        redef fun decorate_tag(v, res, token)
        do
-               res.add_class("nc_v")
                var variable = self.variable
                if variable == null then return null
+               res.add_class("nc_v")
                return variable.infobox(v)
        end
 end
@@ -660,9 +675,9 @@ end
 redef class AVardeclExpr
        redef fun decorate_tag(v, res, token)
        do
-               res.add_class("nc_v")
                var variable = self.variable
                if variable == null then return null
+               res.add_class("nc_v")
                return variable.infobox(v)
        end
 end
@@ -671,9 +686,9 @@ redef class AForExpr
        redef fun decorate_tag(v, res, token)
        do
                if not token isa TId then return null
-               res.add_class("nc_v")
                var vs = variables
                if vs == null then return null
+               res.add_class("nc_v")
                var idx = n_ids.index_of(token)
                var variable = vs[idx]
                return variable.infobox(v)
@@ -683,11 +698,11 @@ end
 redef class AParam
        redef fun decorate_tag(v, res, token)
        do
-               res.add_class("nc_v")
                var mp = mparameter
                if mp == null then return null
                var variable = self.variable
                if variable == null then return null
+               res.add_class("nc_v")
                return variable.infobox(v)
        end
 end
@@ -841,7 +856,7 @@ redef class AType
        do
                var mt = mtype
                if mt == null then return null
-               if mt isa MNullableType then mt = mt.mtype
+               mt = mt.as_notnullable
                if mt isa MVirtualType or mt isa MParameterType then
                        res.add_class("nc_vt")
                end
@@ -918,4 +933,3 @@ redef class AExpr
                return t.infobox(v)
        end
 end
-