https://github.com/jpcima/tinysdl
A tiny SDLang parsing library
https://github.com/jpcima/tinysdl
Last synced: 4 months ago
JSON representation
A tiny SDLang parsing library
- Host: GitHub
- URL: https://github.com/jpcima/tinysdl
- Owner: jpcima
- License: other
- Created: 2016-05-14T21:21:24.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-05-16T17:44:17.000Z (about 10 years ago)
- Last Synced: 2026-01-26T13:55:33.937Z (5 months ago)
- Language: D
- Size: 41 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# TinySDL
TinySDL is not exactly a parser library for the [SDLang](https://sdlang.org/) data language.
I develop this as part of a larger project where the other library does not provide the feature I need, which is operation at compile time.
I only implement the features I need, so you should only use this if you have a good reason not to prefer [SDLang-D](https://github.com/Abscissa/SDLang-D).
Goal of this project:
* Providing a compact yet robust D implementation
* Ability to parse at compile time
* Limited compatibility with SDLang
Non-goals:
* Full compatibility
* Write support
## Parsing and traversal
The library features simple DOM style parsing and traversal.
import tinysdl;
///
Tag root = parse(aSourceText);
foreach (Tag child; root.children) {
///
foreach (Attribute attr; child.attributes) {
///
}
}
## Destructuring
Another way to process homogeneous inputs is to use the provided destructuring functionality.
It is similar in concept to the package [std.getopt](https://dlang.org/phobos/std_getopt.html) of the Phobos standard library.
import tinysdl;
import tinysdl.destructuring;
///
enum source = `example aText="someText" aReal=3.14 aBoolean=true`;
string aText;
double aReal;
bool aBoolean;
destructureAttributes(parse(source).child(0),
option.required, "aText", &aText,
option.required, "aReal", &aReal,
option.required, "aBoolean", &aBoolean);
## Notes
Refer to [tests.d](source/tinysdl/tests.d) and [destructuring/tests.d](source/tinysdl/destructuring/tests.d) for some usage examples.