kicad-developers team mailing list archive
Mailing list archive
XML and S-expression parsing
A recent bug was reported, and it had a lifespan of ten minutes. The
reporter was able to make sense of the DNSLEXER's (S-expression
parser's) exception which was reporting:
a) line number,
b) column offset and
c) expected element.
Here it is:
"I exported my design from PCBnew to freerouting.net successfully and
exported the routed pcb as a session file. But i cannot import the
session file into PCBnew. I get a window: "Expected 'session' in
tiny861.ses line 2 offset 2"..."
Apparently the user went off and actually looked at the file with a text editor, and determined what the problem was.
This speaks volumes for the need to only become dependent on file loading or parsing libraries that meet certain criteria: that can do excellent reporting of invalid input files.
I do not see that in wxXML library as far as *loading* is concerned. But with some work it could be enhanced. It seems to be sitting on top of the C version of expat and they are using a SAX parser underneath for loading. This could be enhanced to throw exceptions with a line number and column offset, but it is some work.
This is work that no one is scheduled to do. In an ideal world you could develop a unified object, which would be the building block of an XML tree, but also could be the base class of any Kicad object, and would also have S-expression functions in it called Format() and Parse(). Something like a unification of specctra.cpp's ELEM and the DELEM in dlist.cpp. This way you could almost save a same document tree in either format simply by calling a different output function.
In the mean time, I rest on my case that I have made before. The error reporting in DNSLEXER is better than the error reporting that I have seen in any XML parser, and this is one reason why I have advocated using S-expression files for Kicad moving forward, for any files that we consider mission critical.
The only reason I chose to use XML for the *export* was to simplify using other tools for reading that exported data. It is data that is not coming to us, it is leaving us, and other tools have the responsibility of reading it.