Ticket #16 (closed enhancement: fixed)

Opened 9 months ago

Last modified 9 months ago

D-style variable formatting & parsing templates

Reported by: Cyborg16 Assigned to: flithm
Priority: major Milestone:
Component: tango.scrapple Version:
Keywords: Cc:

Description

Two sets of templates; one for converting variables to text forms, one for the inverse. See this topic (particularly my later posts) and the unittests for an idea of what it's useful for.

The current version is here. It needs a little bit of work to conform to the D style-guides and possibly a bit of documentation.

Please let me know whether you want to include this in scrapple and if so give me an idea of what changes it needs to fit the guidelines and more importantly be easy for others to use.

As mentioned in the linked post it's a bit specialised, but I've found some uses beside it's intended purpose.

Attachments

shakematrix.d (7.0 kB) - added by Cyborg16 on 02/15/08 11:37:17.
a few changes
paresandunittests.tar.gz (13.4 kB) - added by Cyborg16 on 02/15/08 12:39:25.

Change History

02/12/08 22:37:17 changed by flithm

  • status changed from new to assigned.

Hrmm... looks interesting! So basically this converts to and from char [] and other built in data types, and also does some escape character handling?

I like the associative array stuff.

I'd be happy to include this into tango.scrapple, but a little clean up on the code would be nice. Try to match the Tango style guidelines as much as possible. Some more documentation would be good to.

I was thinking maybe this could end up being called something like: tango.scrapple.text.convert.light.* or lightweight.* or something. I'd also probably move the exception stuff over to tango.scrapple.core.Exception.

Thoughts?

02/13/08 05:48:57 changed by Cyborg16

Eh? Where did my reply go? Great...

I mentioned the following could be added to make the modules more complete: • complex/imaginary type support. Maybe I'll try and get this added to tango first... • cent/ucent support. Again, missing in tango, but is it actually useful to anyone? • template the char-type used for output/input to support wide chars • unicode conversions from tango.text.convert.Utf?

Think I might have a go at the first point. The last two also look like they would be worth adding; maybe I'll get around to it but no promises.

Anyway, thanks for your comments. I'm not entirely sure about the name; it's true-ish of the code but doesn't really describe the purpose (e.g. strings & chars get quoted for lexical purposes).

Oh, also the escape-sequence functions will likely end up in tango, but I'm not too keen on replacing those used in this module with whatever ends up in tango, because even if they don't get changed much now they likely will at some point. Which potentially means more code-bloat... ah well it's not a lot of code.

02/13/08 06:37:32 changed by flithm

No problem on the name. Do you have suggestions? I think it'd be nice to stick with something that is in line with tango.text.convert, and that doesn't conflict with anything already in Tango.

02/13/08 07:38:37 changed by Cyborg16

Dang, just lost another submission. I know my internet connection's playing up, but it wasn't that this time.

I've done some work conforming the code to the tango guidelines (not really a lot to do).

The code probably is slightly heap-abusive, but I don't know how to improve it really. I already try to avoid large numbers of array resizes. Anyway, it probably won't often be used in performance-critical circumstances.

02/13/08 07:44:27 changed by Cyborg16

Not sure about the name. It's purpose is basically text conversions of all types. Of course format should probably be changed since it works completely differently to tango's format, but parse is probably an apt module name. I think both modules should remain separate since their code is disjoint & one of tango's goals is to decouple code to minimise code-bloat.

02/13/08 07:50:40 changed by flithm

Okay Parse sounds reasonable... so since there's the two distinct modules there, how about tango.scrapple.text.convert.ParseTo? and ParseFrom? or something? (Again, totally open to suggestions on that).

At any rate, my suggestion is: clean up the code a bit (tango guidelinesish for things like whitespace, tabbing, ddoc comments, etc), do a little bit more work on the documentation, and I'll have no problems adding it to the repo. Then if you want to add more features no problem!

02/14/08 08:23:37 changed by Cyborg16

Mostly there with the documentation with several examples. Also I realised I'd partially implemented unicode conversions before so I completed that (but still parseTo only reads char types and parseFrom only outputs char types).

I like your suggestion about the parseTo/parseFrom names btw. They better reflect the template type.

02/14/08 13:07:49 changed by Cyborg16

Just about done now. Two questions:

1. Is there any way of running all the unittests or do I have to make my own?

2. Not really a question, but compiling with a load of options gives some errors. The errors didn't actually show up until I added the last option, --doc, but that's probably just because nothing was done otherwise.

> dsss build -debug -debug=UnitTest -C-unittest --doc
Creating imports for DD-tango-scrapple

tango/scrapple => DD-tango-scrapple
+ gunzip -c /usr/local/share/dsss/candydoc.tar.gz | tar -xf -
+ /usr/local/bin/rebuild -Idsss_imports/ -I. -S./ -I/usr/local/include/d -S/usr/local/lib/ -debug=UnitTest -C-unittest  -I/usr/local/include/d -S/usr/local/lib -I/home/cyborg/d/include/d -S/home/cyborg/d/lib  -oqdsss_objs/D -full -Dqdsss_docs/tango/scrapple -candydoc -debug -gc  -explicit -lib tango/scrapple/protocol/PlainTextProtocol.d tango/scrapple/text/convert/TimeStamp.d tango/scrapple/text/convert/parseFrom.d tango/scrapple/text/convert/parseTo.d tango/scrapple/net/http/HttpMultipart.d tango/scrapple/io/Tilde.d tango/scrapple/io/filter/RawCoutFilter.d tango/scrapple/io/Logout.d tango/scrapple/thread/ThreadPool.d tango/scrapple/thread/Message.d tango/scrapple/thread/Actor.d tango/scrapple/util/Test.d tango/scrapple/util/Hex.d tango/scrapple/util/uuid/NameBased.d tango/scrapple/util/uuid/Random.d tango/scrapple/util/uuid/Uuid.d tango/scrapple/util/uuid/Uuid2.d tango/scrapple/util/uuid/Generators.d tango/scrapple/util/uuid/Uuid3.d tango/scrapple/util/Arguments.d tango/scrapple/sys/win32/Registry.d -oflibdebug-DD-tango-scrapple.a
WARNING: Module RawCoutFilter.d does not have a module declaration. This can cause problems
         with rebuild's -oq option. If an error occurs, fix this first.
tango/scrapple/text/convert/TimeStamp.d(68): template tango.scrapple.text.convert.TimeStamp.parseYear(T) does not match any template declaration
tango/scrapple/text/convert/TimeStamp.d(68): template tango.scrapple.text.convert.TimeStamp.parseYear(T) cannot deduce template function from argument types (char*,uint,uint)
Command /usr/local/bin/rebuild returned with code 256, aborting.
Error: Command failed, aborting.

02/15/08 10:18:44 changed by flithm

I don't really have an automated method set up for running unittests yet. If you come up with something though I'd love to add it to the build script.

Errors fixed! I don't use dsss so I didn't notice that before. But thanks for letting me know.

Let me know as soon as the code is updated and I'll add it into SVN.

02/15/08 11:37:17 changed by Cyborg16

  • attachment shakematrix.d added.

a few changes

02/15/08 11:38:17 changed by Cyborg16

OK I'll try to add unittest.

I built the executables in tests/ and adjusted the "shakematrix" test (1: tango.util.time has moved, 2: stopped it dumping several-hundred uninteresting lines about the matrices, 3: halved the randomly generated size since sometimes it can be way too big). See attachment.

Oh btw the ddoc index file doesn't really need to link the documentation for the tests (often this isn't generated anyway).

02/15/08 11:43:02 changed by flithm

Awesome... thanks for the update on the shakematrix, looks good.

02/15/08 12:39:25 changed by Cyborg16

  • attachment paresandunittests.tar.gz added.

02/15/08 12:40:11 changed by Cyborg16

Okay... done.

New attachment, hope you can read tarballs (if not can alter).

02/15/08 12:42:55 changed by Cyborg16

Oh btw, forgot to add that the unittest runs a few tango tests too. I had to hack a tango module to get the tests to run: http://www.dsource.org/projects/tango/ticket/911.

Maybe debug(UnitTest?) should be changed to debug(ScrappleTest?) or similar? (Maybe tango to come to that, but anyway...)

02/15/08 12:58:32 changed by flithm

  • status changed from assigned to closed.
  • resolution set to fixed.

Great! Good job!

Added into SVN, and the project home page has been updated. Are you happy with the description I put on the home page? If not, feel free to send me a new one.

02/16/08 04:27:48 changed by Cyborg16

Yeah that looks good.

btw it might make sense to change debug(UnitTest?) to make it unique in the scrapple modules and tests/dsss.conf. It would probably make sense to separate the scrapple unittests from the tango ones and would be the easiest way to make the unittests run (did you try?).