def
I wrote a program in PostScript for reading/writing JSON data. You can use the following functions:
/.JSON.namech 256 string def
.JSON.namech 43 1 put %+
JSON.namech 45 1 put %-
.JSON.namech 46 1 put %.
On Tuesday, September 3, 2019 at 8:20:26 PM UTC-5, ne...@zzo38computer.org.invalid wrote:
I wrote a program in PostScript for reading/writing JSON data. You can use the following functions:
/.JSON.namech 256 string def
.JSON.namech 43 1 put %+
JSON.namech 45 1 put %-
.JSON.namech 46 1 put %.
I'd be tempted to write '(+) 0 get' instead of '43'. A little less
efficient perhaps, but this part is one-time setup code so not
critical. But using a string makes the comments unnecessary.
def
JSON.utf8 is now implemented (although it doesn't currently convert
surrogate pairs into a single UTF-8 codepoint), and another change as suggested by some of the other follow-up messages to my first message
have also been implemented. Also, the "dot stuffing" of this message is (hopefully) correct now; it was a bug in the NNTP software I was using,
but I have now corrected that bug (hopefully).
Also, I would like to know if you have any use for this, and especially if you have found any bugs in it. (This is not mandatory though; it is public domain, so you are allowed to do whatever you want with it.)
JSON.utf8 is now implemented (although it doesn't currently convert
surrogate pairs into a single UTF-8 codepoint), and another change as suggested by some of the other follow-up messages to my first message
have also been implemented. Also, the "dot stuffing" of this message is (hopefully) correct now; it was a bug in the NNTP software I was using,
but I have now corrected that bug (hopefully).
Also, I would like to know if you have any use for this, and especially if you have found any bugs in it. (This is not mandatory though; it is public domain, so you are allowed to do whatever you want with it.)
The below (between "===BEGIN CODE===" and "===END CODE===") is the[snip]
PostScript program.
===BEGIN CODE===
.JSON.parsech 43 /.JSON.readnum load put %+
.JSON.parsech 125 (>>) cvn load put %}
On Sunday, September 8, 2019 at 4:33:23 PM UTC-5, ne...@zzo38computer.org.invalid wrote:
JSON.utf8 is now implemented (although it doesn't currently convert surrogate pairs into a single UTF-8 codepoint), and another change as suggested by some of the other follow-up messages to my first message
have also been implemented. Also, the "dot stuffing" of this message is (hopefully) correct now; it was a bug in the NNTP software I was using,
but I have now corrected that bug (hopefully).
Also, I would like to know if you have any use for this, and especially if you have found any bugs in it. (This is not mandatory though; it is public domain, so you are allowed to do whatever you want with it.)
I'm not sure how useful it is. Whenever I've needed to send data to postscript,
it has always been fairly easy to output valid postscript code. But I think this *is* a fun little exercise. I spent this afternoon/evening writing my own using the parser combinators. Probably some bugs in edge cases I haven't considered. But simple tests appear to be working! It doesn't do any utf conversion. It doesn't remove whitespace characters.
I'd be curious to see a speed comparison between our two programs (if only
to see how much slower mine probably is). But I'm not quite curious enough
to do it myself.
The next issue is: I don't understand what to do with unicode
characters if they are discovered. It appears that OP's code
reads in the multibyte sequences, constructs the codepoint in
an int, and then truncates that to 8 bits and stores it in a
string. That doesn't seem right, but I can't really think of
anything better. Maybe an option either to leave the utf8 alone,
or convert to arrays of integers? It's not clear to me what
a PostScript program could hope to do with unicode data.
So I haven't written any utf8 handling. If I do add it, I think
it should be added to the parser library itself as an input
filter. The C version has these already.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 294 |
Nodes: | 16 (2 / 14) |
Uptime: | 243:56:07 |
Calls: | 6,626 |
Calls today: | 2 |
Files: | 12,175 |
Messages: | 5,320,318 |