m4rw3r / chomp

A fast monadic-style parser combinator designed to work on stable Rust.
Apache License 2.0
243 stars 19 forks source link

Non `Copy` `Token`s? #56

Open m4rw3r opened 7 years ago

m4rw3r commented 7 years ago

As the title says, any way we can remove the Copy requirement on the Token associated type?

The main drawback of removing it is that most filter-functions will need to operate on borrows (satisfy, take_while and so on), which will introduce some extra typing (one or two extra & or * per filter).

The benefit of removing Copy would be that we can easily do multi-stage parsing (commonly lexer + parser in separate parts) solely in Chomp, relying on the previous parser to construct a new token stream, and this could then refer to the initially parsed data all the way through (depending of course on lifetime requirements of the source itself).

This would be a breaking change, probably 1.0.0 and/or 0.4.0.

m4rw3r commented 7 years ago

Notes:

If we do not remove the Copy requirement, multi-stage parsers have to use the requirement B: Copy + Buffer to work properly which imposes restrictions on the underlying Input. Also possible is to perform the conversion of a buffer into the actual type in the lexer, but this might be a bit too early in the parsing-chain for some formats.¨

Getting some feedback on such a fundamental change as this would be great.

m4rw3r commented 7 years ago

More: