-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add float parser, generalise one_of/.optional() a bit #14
Conversation
@Easyoakland just FYI :) |
Why implement these in an extension trait instead of the same way that a user of the library would implement these (free functions)? Would it not make more sense for some of these functions to use a stack allocated buffer with a maximum size since there are a maximum number of digits? For example u8 max is 256 so 3 chars is sufficient. |
I started with freestanding functions, but the extension trait felt ergonomically superior in the end. One example is for the functions Subjective I'm sure, but I tried both and preferred this!
I didn't add any functions like that; only ones for |
I'm not sure why that's preferable to impl syntax. If you want to specify a type why not do that earlier? fn parser<B>(tok: &mut impl Token...){...}
let a: StrTokens<'static> = "1234".into_tokens();
parser::<String>(&mut a) If the syntax that user's use is different from the library I think that user's defining new combinators (the main thing) becomes a second class citizen. I'm of the opinion that combinators defined in the library should be useful as a big tutorial.
Oh, apparently floats with excessive digits of precision are just rounded so the input can be arbitrarily long. |
I also think the naming Another advantage of free functions is then if it is actually advantageous to have both parse and skip versions of things to make two modules named I'm not sure it is though. Why not only have the skip versions and allow the user to Another alternative could be making these things At this point it might make sense to |
I don't think it's a huge deal either way, but I do agree with the tutorial perspective and promoting freestanding funcs as a good way to do these things. I might revert to freestanding funcs with impl syntax again for this reason; I can't think of a good reason not to just use impl syntax here, really.
This is just opinion but I prefer the current names;
I was going to just have
I guess right now I don't see the point so I'd rather avoid that extra complexity. Would somebody really want to iterate over the tokens that are a part of a float and do something with only a subset of them? I doubt it. (if I kept |
chars::float
to parse floatschars::case_insensitive_eq
for case insensitive token matching.one_of
and.optional()
; allow expressions passed to either to return Options or bools, not just Options.