Skip to content

Improve lrlex codegen errors - #678

Open
ratmice wants to merge 5 commits into
softdevteam:masterfrom
ratmice:lrlex_codegen_errors
Open

ratmice wants to merge 5 commits into
softdevteam:masterfrom
ratmice:lrlex_codegen_errors

Conversation

@ratmice

@ratmice ratmice commented Dec 5, 2026 •

Copy link
Copy Markdown
Collaborator

This is patch is migrates the build_env function in lrlex.
Making it return a Vec<LexerSrcEnvError> instead of storing a Vec<HeaderError> in a variant.

This is similar to one of the patches for lrpar in #674, in preparation for making lrlex codegen a publicly usable unstable api.

The resulting error handling in build_env & parts of this patch is not very pretty.
I was struggling to find a way to improve it, it seems like it ends up a bit worse without ?
But I'm not sure we can do much about it without try blocks

Comment thread lrlex/src/lib/codegen.rs Outdated
pub(crate) fn lex_flags(&self) -> &LexFlags {
&self.lex_flags
self.lexerdef
.lex_flags()

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this is better, I guess it might actually go against the point of LexerBuildEnv,
It's a bit weird to have both a Option<LexFlags> and a cloned copy of it in the same struct.

Initially the idea behind the BuildEnv structs is that by the time it's constructed,
all the various Option types have been resolved to Some value.

What I hadn't really payed attention to, is that it is a bit weird in this case, since lexerdef actually owns the value.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, the fact that it returns an Option<LexFlags> seems to actually be a historical artifact.
It always returns Some.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally feels much cleaner to me in d8f7b94

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant