-
Notifications
You must be signed in to change notification settings - Fork 4
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
Literal whitespace vs literal node #49
Comments
What kind of API do you have in mind? |
I think a...
It's the same signature as of An alternative approach would be to change TBH I think the hard task will be to choose the name. Is |
The requirement is that the inserted fragment is a valid JSON element. Otherwise the writer could end up being confused about the current separator and nesting level. So we could call it |
The name |
On a second thought, I think the code will be more readable if you use the name |
An alternative solution is a
|
That works. |
So, I was playing with lua bindings to trial.protocol (actually it's a bigger project that happens to have JSON support as well and I'm using trial.protocol for that) and I end up finally having an use-case for the
writer
API. So, the following lua code:will print:
So far so good, but the literal API seems incomplete. There are two types of literals — nodes and insignificant linear whitespace. Linear whitespace literals are useful to indent the generated document, but node literals are useful in serialization libraries. For my lua bindings, the user might write a
__tojson()
metamethod as:But that's kind of verbose. And given the type to be serialized has a constant representation, that's also inefficient. I would like to be able to write the following:
But that obviously isn't going to work. When called as part of a bigger object as in:
The output will be:
An invalid JSON.
So, we need a type of literal that accounts for a raw node to be written. I don't think that's hard. I think the bikeshedding to choose the function name is going to be more demanding than the implementation itself.
Anyway, I'm not in a rush to see this issue solved. There are other features besides JSON I have to work on before releasing my project.
The text was updated successfully, but these errors were encountered: