Parsing Cascading Style Sheet like file
-
I have a document in a a *.css (Cascading Style Sheets) like format. Actually it is a personalized css (I call it *.pss), with own tags and properties. here I have an excerpt:
/* CSS like style sheet file *.pss */
@include "otherStyleSheet.pss";/* comment */
[propertyID="72100000"] {
fillColor : #f3f1ed;
minSize : 5;
lineWidth : 3;
}/* sphere */
[propertyID="2352????"] {
lineType : dotted;
}/* square */
[propertyID="2115????"] {
lineType : thinline;
}/* ring */
[propertyID="2315????"] {
lineType : thickline;
[hasInnerRing=true] {
innerLineType : thinline;
}
}- I would like to parse it very easily.
- My task then is to transform that parsed input to an internal data structure, which shall represent that already parsed file.
- When I make changes to that, I would like to overwrite these changes very easily to that file.
Is there already something Ready-To-Use from Qt? What would be the easiest way?
Thanx in advance.
Regards
Ralf -
Hi and welcome
Can I ask if it must be pss ?
Sine you want to parse it easy, its not the most easy start making a new format.As far as I know - there is no Qt easy way of parsing in/write out such custom format.
Of cause you can build your own parser/serializer but it get complex pretty fast.So you could go much easier (IMO) if you used xml or json as
that loads the data into a structure that you can modify and
write back to file without much hassle.Also you have the classic issue with comments. They are more part of the file than the data itself so to keep them when file
is rewritten, special care must be taken.With xml that supports comments, you get this for "free".
Of cause It all depends what you really want. if the job IS to write such parser for pss then just forget what i just said :)
-
@Ralf
Oh, :(
Well in that case I would download source code for whole Qt
and have a look of what they use for
the qss (css) parsing and see if some could be reused. ( i have no idea)Also
http://www.codeproject.com/Articles/20450/Simple-CSS-Parseris a good read (IMO) for toughs about writing such parser.
Good luck