manoelcampos / xml2lua

XML Parser written entirely in Lua that works for Lua 5.1+. Convert XML to and from Lua Tables 🌖💱
MIT License
287 stars 73 forks source link

Issue while parsing Vulkan headers #2

Closed onatto closed 7 years ago

onatto commented 7 years ago

Found this bug while parsing the Vulkan headers, here's the minimal repro, modified from example code:

dofile("xml.lua")
dofile("handler.lua")

---Recursivelly prints a table
--@param tb The table to be printed
--@param level Only internally used to indent the print.
function printable(tb, level)
  level = level or 1
  local spaces = string.rep(' ', level*2)
  for k,v in pairs(tb) do
      if type(v) ~= "table" then
         print(spaces .. k..'='..v)
      else
         print(spaces .. k)
         level = level + 1
         printable(v, level)
      end
  end  
end

xmltext = [[ <param><type>VkFramebuffer</type>* <name>pFramebuffer</name></param> ]]

--Instantiate the object the states the XML file as a Lua table
local xmlhandler = simpleTreeHandler()

--Instantiate the object that parses the XML to a Lua table
local xmlparser = xmlParser(xmlhandler)
xmlparser:parse(xmltext)

--Recursivelly prints the table
printable(xmlhandler.root)

Output using Lua 5.1: param=*

manoelcampos commented 7 years ago

Your XML is malformed. You must remove the * after the tag. This is a very basic parser that doesn't validate your XML. It just expects that you provide a valid one.