Closed jasoncarr0 closed 6 years ago
I was focusing on my use case of parsing SDL. I'm making some changes now for version 2.0.2 and will publish shortly. Example code:
Tag t = new Tag("myObject");
t.addValue(SDL.value('g'));
t.addValue(SDL.value(LocalDateTime.now()));
t.addValue(SDL.value("A \n multiline string", true));
I've pushed the changes to the develop branch. Would you mind cloning the repo and doing a mvn install
from the develop branch to get 2.0.2-SNAPSHOT in your local mvn and try it out. I've not fully tested yet so don't want to publish to mvn central until it's been used a bit.
Thanks, I'll try it out. My use case involves bidirectional transformations, so I wanted to be able to create tags.
now that I've taken a little time play about with it I'm thinking about changing the API a little so that instead of using:
final Tag child = new Tag("child");
child.addValue(SDL.value(dateTime));
child.addValue(SDL.value(541L));
final Tag t = new Tag("my", "thing");
t.addValue(SDL.value('g'));
t.addChild(child);
t.setAttribute("flt", SDL.value(0.0f));
you could write:
Tag tag = SDL.tag("thing")
.withNamespace("my")
.withValue(SDL.value('g'))
.withChild(SDL.tag("child")
.withValues(SDL.value(dateTime), SDL.value(541L))
.build()
)
.withAttribute("flt", SDL.value(0.0f))
.build();
This design feels a lot nicer to work with for me. Any thoughts? Will this be better for you?
I'll push it now
That would be great. I think in my use case I may end up putting a facade in front to abstract the details more anyway, but that is definitely a lot nicer to work with than the imperative method.
Actually one issue here is that it's a bit error-prone with strings. I think there should be two methods for SDL.value instead, one for parsing, one for going from java types, rather than an optional flag for two different behaviours on strings.
I've published 2.1.0 to maven central with the changes I proposed the other day. As well as #7 which may come in handy. I was considering having something like a SdlWriter or SdlSerializer class with options for outputting SDL with indentation/newlines (pretty) or minified, enabling/disabling comments, and specifying line comment style.
enum Comment {
CPP,
SHELL,
LUA,
NONE
}
SdlSerializer sdl = new SdlSerializerBuilder() // default to pretty with comments enabled as CPP style
.pretty(true)
.comments(LUA)
.build();
sdl.serialize(tag);
however for now there's enough to get going.
The SDLValue class is not public, but you require it in your addValue method. The original repo does not have this issue. There does not appear to be a way to work with these SDL trees by hand (e.g. to write SDL out), so this is a major issue.