Page 1 of 1

[ZScript] Parse INI-style data in lumps

PostPosted: Tue Jul 17, 2018 12:39 am
by argv
I've written a library for parsing INI-style files from ZScript. See it on GitHub.

Re: [ZScript] Parse INI-style data in lumps

PostPosted: Tue Jul 17, 2018 1:09 am
by Nash
Sick!!! Thanks for putting this out. I'll most definitely have a use for this (with credits to you, of course).

Re: [ZScript] Parse INI-style data in lumps

PostPosted: Sun Jul 22, 2018 3:17 am
by argv
I've added several more features! Check out the updated README.

Re: [ZScript] Parse INI-style data in lumps

PostPosted: Sun Jul 22, 2018 5:30 am
by Nash
Thanks so much argv. Just curious, would it be hard to write a JSON or XML parser too?

Re: [ZScript] Parse INI-style data in lumps

PostPosted: Sun Jul 22, 2018 5:56 pm
by argv
Impossible to do correctly, actually. ZScript cannot (as far as I know) decode UTF-8, which all JSON and most XML is encoded in.

Even with that, though, it would be very hard. Parsers in ZScript have to be written entirely by hand, since there are no parser generator tools or libraries for it (and they'd probably be agonizingly slow anyway). INI is a pretty trivial format, and it takes a fair bit of ZScript code to parse even that.

GZDoom actually comes with a JSON parser, which it uses for saved games. GZDoom save files are zips containing JSON files. It's not exposed to ZScript, though. If you want that, you could ask Graf to expose it.

Re: [ZScript] Parse INI-style data in lumps

PostPosted: Mon Jul 23, 2018 7:03 am
by The Zombie Killer
argv wrote:Impossible to do correctly, actually. ZScript cannot (as far as I know) decode UTF-8, which all JSON and most XML is encoded in.

Even with that, though, it would be very hard. Parsers in ZScript have to be written entirely by hand, since there are no parser generator tools or libraries for it (and they'd probably be agonizingly slow anyway). INI is a pretty trivial format, and it takes a fair bit of ZScript code to parse even that.

GZDoom actually comes with a JSON parser, which it uses for saved games. GZDoom save files are zips containing JSON files. It's not exposed to ZScript, though. If you want that, you could ask Graf to expose it.

I have a number of classes and functions I've written that you may find useful for this, if you're interested in tackling it. Namely, I have Stream classes that support UTF-8, a hash map, a tokenizer, a StringUtility class that can handle Unicode and convert it to UTF-8, etc.

You can find it here: https://gitlab.com/TheZombieKiller/zk/t ... er/zk-core

I definitely agree that getting the JSON parser already present in the engine exposed to ZScript is the superior solution, though.