Skip to content

Make codegen pub - #672

Draft
ratmice wants to merge 6 commits into
softdevteam:masterfrom
ratmice:codegen_pub
Draft

ratmice wants to merge 6 commits into
softdevteam:masterfrom
ratmice:codegen_pub

Conversation

@ratmice

@ratmice ratmice commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

This is a first attempt at my remaining todo list.

It tries to make codegen pub, and remove the usage of hidden API in nimbleparse.
It does so by usage of the codegen process and selectively unhiding some API we've worked towards making nicer over this development cycle (the header::Value structure and header errors).

The actual errors that are going to be emitted here will very likely need some work,
But I did do a basic smoke test run of nimbleparse with some erroneous input.

The usage of codegen might seem weird, nimbleparse doesn't actually generating any code...
We kind of use it as a "PreBuilder" for RTParserBuilder which does a couple of things

  1. Defaulting values like %grmtools{yacckind: ...} by parsing the %grmtools section.
  2. Building and obtaining the resulting AST
  3. Checking header keys for validity

As an example of step 3, we can add an invalid key to one of the examples

%grmtools{
    cfgrammar.foo: "There really is no cfgrammar.foo key",
}

$ cargo run --bin nimbleparse -- ./lrpar/examples/calc_parsetree/src/calc.{l,y}

[Error] in ./lrpar/examples/calc_parsetree/src/calc.y
4|     cfgrammar.foo: "There really is no cfgrammar.foo key",
       ^^^^^^^^^^^^^ Unused keys in %grmtools section: cfgrammar.foo

I had hoped to before making this stuff pub, get a version of nimbleparse_lsp ready to test with.
But that was before I had noticed the hidden API usage in nimbleparse. In this regard, there isn't
much that could go wrong in nimbleparse_lsp that wouldn't also run afoul of nimbleparse itself.

I would say that the codegen error handling is not totally pretty here.
I should probably go through CTParserBuilder and double check it's error handling,
to see if I missed any nicer mechanisms. Despite that, it does seem to come out as a net negative lines of code 👏

@ratmice
ratmice marked this pull request as draft November 29, 2026 12:12
@ratmice

ratmice commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator Author

Besides a more exhaustive check of the errors, this probably also needs a read through the rustdoc output.
Because of that I guess that I should mark it as draft.

At a first glance, a lot of the codegen docs are in fact missing.

Comment thread lrpar/src/lib/codegen.rs Outdated
}

/// A Parser source environment is the first step in a *Sans-I/O* interface to source code generation.
///

@ratmice ratmice Nov 29, 2026 •

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 think I'm probably going about this the wrong way, in that I think the "first step"
parts here and elsewhere that i describe the sequence of order of structures in the codegen process
really belong in the leading module documentation,

because these structures being in alphabetical order makes it really confusing.

I'll continue working on this tomorrow.

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 did a second pass in a433065

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.

2 participants