LeopoldArkham / Molten

[WIP] Molten - Style-preserving TOML parser.
Apache License 2.0
40 stars 8 forks source link

Add static "from" methods and allow writing to files #31

Open LeopoldArkham opened 6 years ago

LeopoldArkham commented 6 years ago

The tests will need to be updated to use these new methods

markcol commented 6 years ago

Taking #5 in mind, should Parser::::from() automatically parse the data? For example, the test in parser.rs line 757, could look like either of these::

let _ = Parser::from(text).parse();

or

let _ = Parser::from(text);

The later feels better/more ergonomic to me.

If you want to make all of the Parser functions private, you could add a from() and from_file() onto the TOMLDocument, and then have the document control when parsing happens. It depends on what shape the API would be for the users.

LeopoldArkham commented 6 years ago

Actually, from() and from_file() could even be free functions, that's how most parsing libraries seem to do it:

extern crate molten;

let doc = molten::from_file("cargo.toml");

Seems like the best solution to me!

markcol commented 6 years ago

I agree. I'm working on it.

LeopoldArkham commented 6 years ago

Great! Note that from_file may have to become from_reader, otherwise the references in the parsed document will outlive the original file