Open m4rw3r opened 8 years ago
I should probably rename this branch, it is no longer an experiment :)
How to properly handle the case of peek_next
+ switch
? All the branches of the switch
return parsers of different types (and many times different sizes too). Forcing the use of boxed()
on each of the returned parsers would be far from ideal.
Example:
macro_rules! ret { ( $e:expr ) => { any().then(ret($e)) } }
peek_next().bind(|c| match c {
b'{' => ret!(Token::StartObject),
b'}' => ret!(Token::EndObject),
b'(' => ret!(Token::StartArray),
b')' => // ...
b'"' => quoted_string(),
_ => tagged!(b"true", Token::True).or(
tagged!(b"false", Token::False).or(
tagged!(b"null", Token::Null).or(
number.or(whitespace))))
})
Seems like https://docs.rs solves the documentation issue, except for providing documentation for master
of each of the two versions.
Great stuff! It looks though as this implementation would currently suffer from the lack the "anonymized enums" capability of impl Trait
for merging results of potentially different anynomized types (for object-safe traits), this is something that's been discussed in the tracking issue recently. Otherwise you're basically back to boxing once you have several anonymised results to deal with, as shown in your example above :)
I hope I can find the time soon to continue working on Chomp.
@aldanor I have encountered that issue, or something close to it, with the sep_by
parser where the separating parser is not present for the first time it iterates. The solution was to create a small enum-wrapper which matches on a contained Option<P: Parser>
and calls the nested parser if present. This did not seem to cause any performance-degradation.
But the more general case will require boxing, if no object-safe enum can be used. Maybe a macro can be used to build an enum for the static case to avoid boxing.
combinators::bounded::ParserConstructor<I>
is now implemented by FnMut
and the special parser for sep_by
This is the
impl Trait
based monad implementation of Chomp for Rust Nightly. It is not intended to become the 1.0.0 of Chomp, currentmaster
is using the monad-like syntax where an input is manually threaded. Instead version 2.0.0 will be the full-monad. See #50 for the reasoning why.Still heavily work in progress. An alpha is intended for release once the documentation-issue is solved.
[ ] Tests for
MonadPlus
laws.Also write the laws in the documentation for the
Parser
trait.Parser::inspect
andparsers::*
Parser::then
,Paser::map
,Parser::map_err
,Parser::skip
andParser::boxed
[ ]
From::from
support in fundamental combinatorsThis needs to be investigated, it is definitely a good thing in general, but being able to not have to use type-inference on some chains would be awesome (investigate default types).
parse!
macro.1.0.0
and this2.0.0
, with links between the two so it is easy to look at both of them (and make sure that users understand which works on stable and which one on nightly, and their benefits and drawbacks).1.0.0
and2.0.0
branch at the same time.ParserFactory
trait as a parameter to repeating combinators likemany
instead of using aFnMut() -> impl Parser<I>
generic. This would get rid of the requirements onfn_traits
andunboxed_closures
features.peek_next
+switch
having differently typed parsers for each branch in theswitch
?