rgrinberg / bencode

Bencode (.torrent file format) reader/writer in OCaml
24 stars 4 forks source link

reworked interface for streaming parsing #2

Closed c-cube closed 10 years ago

c-cube commented 10 years ago

I changed a lot of things in the way Bencode_streaming works, by adding Bencode_token (which deals only with "events" in the following type) and combining it with a simple stack parser that reads tokens and builds tree structures. I also added some tests and a few helper functions to Bencode itself.

type token =
  [ `I of int
  | `S of string
  | `BeginDict
  | `BeginList
  | `End
  ]

A new Changelog.md file has also been added.

rgrinberg commented 10 years ago

Do you mind updating the tests as well?

ocamlbuild -use-ocamlfind bencode.cma bencode.cmxa bencode.a bencode.docdir/index.html
Finished, 34 targets (0 cached) in 00:00:00.
+make test
ocamlbuild -use-ocamlfind -package oUnit lib_test/test_ounit.native
+ ocamlfind ocamlc -c -g -package oUnit -I lib_test -I lib -o lib_test/test_ounit.cmo lib_test/test_ounit.ml
File "lib_test/test_ounit.ml", line 9, characters 8-23:
Error: Unbound value BS.parse_string
Command exited with code 2.
Compilation unsuccessful after building 8 targets (0 cached) in 00:00:00.
make: *** [ounit] Error 10
c-cube commented 10 years ago

Done. What do you think about the old and new interfaces?

rgrinberg commented 10 years ago

I think it's very good. I would have preferred Decode.result be a polymorphic variant because the constructors that it uses are very "common". For example ParseError, StateError, Error could perhaps be unified. It's not a big deal though.

Also in the top level I think we should have a "toplevel" Bencode module that we pack (maybe manually?) with the various submodules as Easy, Streaming, etc.

Also, I think you skipped a version number somewhere...

c-cube commented 10 years ago

On 2 mai 2014 05:17:11 UTC+02:00, Rudi Grinberg notifications@github.com wrote:

I think it's very good. I would have preferred Decode.result be a polymorphic variant because the constructors that it uses are very "common".

It can still be done! :)

Also in the top level I think we should have a "toplevel" Bencode module that we pack (maybe manually?) with the various submodules as Easy, Streaming, etc.

Yes, I agree, it could also load a few printers (to make encoded values more readable).

Cheers!

Simon