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 */
/* comment */
fillColor : #f3f1ed;
minSize : 5;
lineWidth : 3;
/* sphere */
lineType : dotted;
/* square */
lineType : thinline;
/* ring */
lineType : thickline;
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.
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 :)
@mrjj Unfortunately the format is fixed and not choosen by myself. So XML and JSON is ruled out :(
Then I start to write my own serializer.
Thnx for the answer.
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)
is a good read (IMO) for toughs about writing such parser.