Header recoverykind#550
Conversation
1cc1df3 to
53989b4
Compare
|
Is there any way to build a test to cover this functionality? |
|
I was struggling to consider how to test it, because we can't really get the recoverykind out of the ctbuilder. I think we can kind of modify cttests to do something, but it doesn't yet support sending recoverer to the builder. Anyways, you remind me I tested nimbleparse, by hand but forgot to test CTParserBuilder, looks like there is some kind of an issue with marking used there; but it doesn't jump out at me yet. (Edit: Oops, I was just testing on master which of course doesn't use recoverer yet) |
|
I wonder about an approach involving |
|
So, my gut leaning towards using the I figure we if we pass the That'll give testing crates everything they need to construct an |
It does sound like it's quite probably the way to go, even in the context of this PR? |
|
Assuming it works, running into some silly lifetime issues though. |
|
So, this works for our testing purposes I was not able to make it That means we can't easily play around with this in the testsuite without making it public. Going to go ahead and mark this as draft now, unless we can avoid making it Edit: I still have yet to test that this is enough to build an |
|
So, in my first attempt there are a few things missing to be able to actually
In theory we could maybe add the lex file path to the header from |
| &'y YaccGrammar<StorageT>, | ||
| &'y StateTable<StorageT>, | ||
| &'y StateGraph<StorageT>, | ||
| Option<PathBuf>, |
There was a problem hiding this comment.
Adding this PathBuf for lexer_path is kind of a hack, we're accruing lots of parameters,
I'm not sure if in this case we could add the lexer_path to Lex's Header and we could give CTParserBuilder a copy of CTLexerBuilders header (we may actually need to!)
Anyhow what i'm trying to say is we could consider putting the lexer path inside the header too instead of having a specific parameter for it.
There was a problem hiding this comment.
what i'm trying to say is we could consider putting the lexer path inside the header too
I don't want to be too dogmatic about this, as this might be the right solution, but I tend to lean towards thinking of the path as an "external" thing rather than part of the header.
| let lexer = lexerdef.lexer(src); | ||
| let errs = pb.parse_noaction(&lexer); | ||
| if !errs.is_empty() { | ||
| return Err(format!("{:?} while parsing src: {}", errs, src).into()); |
There was a problem hiding this comment.
It is also worth noting that this whole, don't build the parser at all unless it parses these things is fairly unforgiving. It doesn't leave much for ways to poke the broken parser. I'd say it is no replacement for a testing mechanism. But I do see the appeal of "do not generate the parser unless it fulfills these baseline functionality".
In that sense, I'm uncertain about the example here.
| .rust_edition(lrlex::RustEdition::Rust2021) | ||
| .lrpar_config(|ctp| { | ||
| ctp.rust_edition(lrpar::RustEdition::Rust2021) | ||
| .inspect(Box::new(move |_, recov, grm, stable, _, lexer_path| { |
There was a problem hiding this comment.
Dumb question: are we currently thinking of this as an internal or a potentially external API? If the former, I would consider this a "test" rather than an "example".
There was a problem hiding this comment.
Because we can't #[cfg(test)] it easily and use it from within cttests, that makes it pub, so this is experimenting with considering it an external API.
Hence my concern above about the example being pretty unforgiving, and not likely something you'd want to use as a replacement for #[test], in other words I worry that it will be taken as a test rather than a way to abort compilation.
Maybe the right thing to do is to run the cttests recoverykind tests under a #[test] rather than within build.rs, so we can avoid making it pub until we're ready, I suppose it is already dealing with non-source-dir paths to the generated yacc files.
There was a problem hiding this comment.
The plan to move it into a #[test] under lrpar/cttests/src/lib.rs doesn't actually work,
because while cttests lives under the lrpar/ in the file system, from the cargo/crate perspective they
are completely separate crates, so adding it to #[cfg(test)] still doesn't make the callback visible within cttests.
There was a problem hiding this comment.
I guess I could do it within a #[test] under lrpar/
|
So with the change scaled back down to just doing testing, and avoiding adding any new pub items, I went ahead and unmarked as draft. |
| self | ||
| } | ||
|
|
||
| #[cfg(test)] |
There was a problem hiding this comment.
Do we need to make this doc(hidden) too? I think it will show up in rustdoc otherwise (but I might be wrong).
There was a problem hiding this comment.
We shouldn't need to, by default rustdoc only documents the specified cfg values, or the ones specified by cfg(doc)
|
Please squash. |
207eb32 to
cf3cdaf
Compare
|
Squashed. |
This implements reading the `recoverer` field from the grmtools section for nimbleparse and `CTParserBuilder`. It also adds a `recoverer` field to cttests which calls the `recoverer` method in `CTParserBuilder`. As well as tests checking both the builder methods, and the `%grmtools` section value.
cf3cdaf to
367f715
Compare
|
Should be fixed in 367f715. Apparently rustfmt actually wanted that random indentation change. |
This adds one commit(1cc1df3) on top of the patches PR #549.
Adding
RecoveryKindas a allowed/working field within the%grmtoolssection.Edit: Rebased this on master