src: use MFormalType for type checks when it makes sense
[nit.git] / src / highlight.nit
index 5e3acf1..f4268c0 100644 (file)
@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# Highliting of Nit AST
+# Highlighting of Nit AST
 module highlight
 
 import frontend
@@ -29,6 +29,14 @@ class HighlightVisitor
        # Used to have a really huge and verbose HTML (mainly for debug)
        var with_ast = false is writable
 
+       # Prefixes used in generated IDs for line `<span>` elements.
+       # Useful if more than one highlighted code is present in the same HTML document.
+       #
+       # If set to the empty string, id for lines are disabled.
+       #
+       # Is `"L"` by default.
+       var line_id_prefix = "L" is writable
+
        # The first line to generate, null if start at the first line
        var first_line: nullable Int = null is writable
 
@@ -40,6 +48,8 @@ class HighlightVisitor
                html.add_class("nitcode")
        end
 
+       # The entry-point of the highlighting.
+       # Will fill `html` with the generated HTML content.
        fun enter_visit(n: ANode)
        do
                n.parentize_tokens
@@ -82,7 +92,8 @@ class HighlightVisitor
 
                                # Add a div for the whole line
                                var tag = new HTMLTag("span")
-                               tag.attrs["id"] = "L{cline}"
+                               var p = line_id_prefix
+                               if p != "" then tag.attrs["id"] = "{p}{cline}"
                                tag.classes.add "line"
                                stack2.add(html)
                                html.add tag
@@ -320,6 +331,7 @@ redef class MModule
                return res
        end
 
+       # The module HTML page
        fun href: String
        do
                return name + ".html"
@@ -377,6 +389,7 @@ redef class MClassDef
                return res
        end
 
+       # The class HTML page (an anchor in the module page)
        fun href: String
        do
                return mmodule.href + "#" + to_s
@@ -423,6 +436,7 @@ redef class MPropDef
                return res
        end
 
+       # The property HTML page (an anchor in the module page)
        fun href: String
        do
                return self.mclassdef.mmodule.href + "#" + self.to_s
@@ -857,7 +871,7 @@ redef class AType
                var mt = mtype
                if mt == null then return null
                mt = mt.as_notnullable
-               if mt isa MVirtualType or mt isa MParameterType then
+               if mt isa MFormalType then
                        res.add_class("nc_vt")
                end
                return mt.infobox(v)