-
-
Notifications
You must be signed in to change notification settings - Fork 294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch from XML to S-Expressions file format #193
Conversation
Shouldn't dates be quoted? E.g. see here |
Some other remarks: (name (locale "") "R-US")
(description (locale "") "Resistor American (IEEE 315)")
(keywords (locale "") "resistor,resistance") I don't quite get that. Shouldn't that be I also wonder whether in some cases more newlines would be better: (signal 6d776f4d-2a7c-4128-a98a-dbb1dd861411 (name "2") (role passive)
(required true) (negated false) (clock false) (forced_net "")
) Maybe this would be better like this: (signal 6d776f4d-2a7c-4128-a98a-dbb1dd861411
(name "2")
(role passive)
(required true)
(negated false)
(clock false)
(forced_net "")
) It would also help when doing diffs. Regarding this one: (disp none)
What about flags? (signal 1c1c7abc-7b40-4f92-b533-f65604644db7 (name "1") (role passive)
(required true) (negated false) (clock false) (forced_net "")
) Maybe (signal 1c1c7abc-7b40-4f92-b533-f65604644db7 required (name "1") (role passive)
(negated false) (clock false) (forced_net "")
) On the other hand it might make the format less generic and harder to parse. And a general comment, I'd use two spaces for indentation, one is a bit hard to see when dealing with larger structures. |
I saw no reason to quote them because the format of dates is well known (contains only letters, digits, :, - and +) and thus is always a valid S-Expression token. |
I expected that question 😃 I already spent some time to improve the format of localized strings (name, description, keywords), but unfortunately I didn't found a good solution. Actually the main question is: How should the localizing of these attributes work? My current idea is that for each library element there are fields for "name", "description" and "keywords" without a specific locale. So if you create libraries only for yourself, you can for example fill these fields with German words. In addition, translated strings can optionally be added, e.g. for your libraries someone could add English translations. For that system, the most reasonable file format would probably look like this:
But this is really ugly to parse, because the text is not always at the same index of the node (index 0 without locale, index 1 with locale). Of course it would be possible to either take the count of child nodes, or the type of each child node into account, but it feels like a workaround to do that. If the order of the child nodes is swapped, parsing gets easier, but IMO the file looks less intuitive:
Another solution is to always write down the locale, but without an extra child node, but this also looks strange:
Maybe it would make sense to make the locale mandatory, so every string has a locale defined?
But this would bring up a new question: Which locale should be used if the user's locale is not found? So if you have set your default locale to "cs_CZ", which of the two available locales "de_CH" and "en_US" should be displayed? When having default/fallback name/description/keywords, these will be used in such cases. Do you have a good answer for these questions? :)
It helps doing diffs on short files. But when adding more newlines, many files get much longer (e.g. >1000 lines), which is also not nice. I think creating nice looking files is a trade-off between length of lines and count of lines.
Of course this would improve readability, but here I also see a trade-off between file size and readability. Optimal for file size would be zero indentation (and even no newlines), optimal for readability ~2-4 spaces. So for me, 1 space seems to be a good compromise (keep in mind that you will probably never write such files by hand, and even reading such files should not be daily business).
Right.
Looks interesting, need to think about it... ;) EDIT: Thought about it ~10seconds 😄 and my answer is: It makes files less self-documented. If a flag is missing, it's not visible that there could be such a flag. A boolean value (e.g. |
377e094
to
0379c4e
Compare
Ok now I updated the format of localized strings by making the "locale" node optional:
IMO the files look much better this way, but of course parsing feels a bit crappy now... What do you think @dbrgn? Btw, the links from the first post above always point to the latest file format, just check out these files again to see the difference. |
Don't you initially parse the S-Expression into a generic nested key-value tree? In that case parsing would not make a difference. In general I like the approach with the optional locale node. |
Yes, I do.
"Low-level" parsing does not make a difference, but serializing and deserializing of objects is a bit ugly. See 3717032, this is the change needed to make the "locale" node optional. |
} | ||
} | ||
|
||
QList<SExpression> SExpression::getChilds(const QString& name) const noexcept |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't that be getChildren
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, the plural form is not always the singular form with an 's' appended 😭 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Welcome to the brave world of stemming and pluralization 😆
That isn't too bad though :) |
0379c4e
to
ff879eb
Compare
I think this should be ready now! ✨ I have even added the new mime type @dbrgn @rnestler Someone interested in providing a syntax highlighting config for Vim? Or does Vim also support the GtkSourceView language specs? |
All serialization core classes are changed to work with S-Expressions instead of XML. All other classes will follow soon.
Affected classes: - librepcb::Angle - librepcb::Length - librepcb::Ratio
This can be used to enable syntax highlighting for *.lp files in some text editors (e.g. Gedit on Ubuntu). Just execute the shell script to install the language specs.
Convert all XML files to S-Expressions
ff879eb
to
8dea953
Compare
Example files:
Fixes #192