Lrpar codegen - #657
Conversation
| &self.stable | ||
| } | ||
|
|
||
| pub(crate) fn take_parser( |
There was a problem hiding this comment.
This one's interesting because it consumes self. Why/when do we use it in that way?
There was a problem hiding this comment.
This is for the return values to CTParserBuilder::build we construct a CTParser from it in the Ok case.
And I think we need to take ownership of the StateTable and StateGraph for CTConflictsError in some of the error cases too.
There was a problem hiding this comment.
I was wondering if fn finish(self) -> (YaccGrammar, StateGraph, StateTable) or finished might be a better
name, since technically it's taking more than just the parser?
I don't know if it's really finishing or finalizing anything, but maybe it conveys better that we're done with self and taking ownership of all the interesting values.
|
My attempt to avoid conflicts didn't work (We modified lines that are removed too!), But this does run though |
| match syn::parse_str::<proc_macro2::Ident>(mod_name) { | ||
| Ok(s) => s, | ||
| Err(e) => return Err(format!( | ||
| "CTParserBuilder::mod_name(\"{}\") is not a valid rust identifier due to '{}'", |
There was a problem hiding this comment.
So I think ideally we'd be able to retain some mention of CTParserBuilder in this error text, which
in my patch series we've lost, to me it indicates that mod_name might want to be routed through Header, so it can pick up a location of CTParserBuilder or so.
There seem like a number of places in this patch where the origin of some error condition might be improved, but I'm hesitant to try and do too much/everything in this specific series.
There was a problem hiding this comment.
I agree: we don't have to do everything in one go.
|
I suspect it's worth merging |
|
I'm actually not really worried about the rebase, since all the conflicts should be of the form I believe that 5143009 should bring it in line with the current master branch |
|
I think we're probably ready to squash? |
|
I think so, but I wanted to think given all the simplifications we've done, whether we can move back to the more simpler model like we started with with I think it might be feasible now to have the two-phase thing, but I kind of like the I'd like to mull that over a bit, hear what you think first. |
I think this is probably as reviewable as I'm going to manage to make this large of a patch.
The basic idea behind this patch is to have a kind of "functional pipeline", for doing code generation,
(SrcEnv?, BuildEnvArgs) -> BuildEnv? -> Codegen(SrcEnv, BuildEnv) -> rust_code?A bit of an oversimplification, as there are some other minor details...
BuildEnvArgsis kind of a minimalist equivalent of the current builder, it's just full ofOptionvalues.BuildEnvis full ofderivedvalues, it mostly strips off theOption, but it also contains values likeASTWithValidityInfothat are derived from all the other args.Codegenthen owns theYaccGrammar,StateTableandStateGraphs, which you can take ownership of after generating code.This may not be totally perfect basis for traits and external usage, for example it currently returns
Box<dyn Error>instead of typed errors. But it should be a pretty faithful conversion of the existing process, into a more targeted/self contained module.