doc: Commands tests use `test_frontend`
[nit.git] / lib / dom / parser.nit
index 4a64cc5..94f718b 100644 (file)
@@ -60,7 +60,8 @@ class XMLProcessor
                        else
                                var st = pos
                                var end_pc = ignore_until("<") - 1
-                               var pc = new PCDATA(src.substring(st, end_pc - st + 1).trim)
+                               var loc = new Location(line, line_offset)
+                               var pc = new PCDATA(loc, src.substring(st, end_pc - st + 1).trim)
                                if stack.is_empty then
                                        pc.parent = doc
                                else
@@ -81,6 +82,7 @@ class XMLProcessor
                var c = src[pos]
                if not c == '<' then return new XMLError(st_loc, "Expected start of tag, got `{c}`")
                pos += 1
+               if pos >= src.length then return new XMLError(st_loc, "Malformed tag")
                c = src[pos]
                if c == '!' then
                        # Special tag
@@ -121,7 +123,7 @@ class XMLProcessor
                                var cdend = ignore_until("]]>")
                                pos += 3
                                if pos >= srclen then return new XMLError(st_loc, "Unfinished CDATA block")
-                               return new CDATA(src.substring(cdst, cdend - cdst))
+                               return new CDATA(st_loc, src.substring(cdst, cdend - cdst))
                        else if spe_type == "DOCTYPE" then
                                pos += 7
                                return parse_doctype(st_loc)
@@ -185,7 +187,6 @@ class XMLProcessor
                                end
                        end
                else
-                       if tag_name.has("xml") then return new XMLError(st_loc, "Forbidden keyword xml in Processing Instruction")
                        var cont_st = pos
                        var cont_end = ignore_until("?>")
                        if cont_end == -1 then
@@ -235,11 +236,11 @@ class XMLProcessor
        # Parses an xml tag name
        private fun parse_tag_name(delims: Array[Char]): String do
                var idst = pos
-               var c = src[pos]
                var srclen = src.length
-               while pos < srclen and not c.is_whitespace and not delims.has(c) do
+               while pos < srclen do
+                       var c = src[pos]
+                       if c.is_whitespace or delims.has(c) then break
                        pos += 1
-                       c = src[pos]
                end
                return src.substring(idst, pos - idst).trim
        end
@@ -262,7 +263,7 @@ class XMLProcessor
                var st_loc = new Location(line, line_offset)
                if pos >= srclen then return new BadXMLAttribute(st_loc, "Unfinished attribute name")
                # FIXME: Ugly, but as long as it remains private, it is OK I guess
-               if endtags.has(src[pos]) then return new XMLAttributeEnd("")
+               if endtags.has(src[pos]) then return new XMLAttributeEnd(st_loc, "")
                var attrname_st = pos
                while pos < srclen and src[pos] != '=' and not endtags.has(src[pos]) do pos += 1
                if pos >= srclen then return new BadXMLAttribute(st_loc, "Unfinished attribute name")