Skip to content

Conversation

@ratmice
Copy link
Collaborator

@ratmice ratmice commented Mar 12, 2025

This moves away from a /* CACHE INFORMATION comment. Instead it uses a module and places all the data into constant values. Because the quote crate relies heavily on proc-macro2 token types which lacks a comment token. So it doesn't actually have any representation for comments.

One trick is to the attribute for a doc comment but hide the doc comment in some inner scope.
This is fairly hacky, and inconvenient because rustdoc still will want it to be properly formatted documentation, there is also the possibility that it the tools become smart enough to figure out that these doc strings are unreachable.

fn foo() {
	#[doc = "we can use a doc comment via an attribute in place of a normal comment"]
	mod _ignore_this_module_{}
}

Instead this patch migrates the cache information to a module with constant values. This module is nested within the lrpar_mod! module in order to avoid introducing multiple modules with the cache_information name at top-level when generating multiple parsers.

mod mod_name_y {

   #[allow(unused)]
   mod cache_information {
      ...

      const ERROR_ON_CONFLICTS: bool = true;
      ...
   }
}

@ratmice ratmice marked this pull request as draft March 12, 2025 08:28
@ratmice
Copy link
Collaborator Author

ratmice commented Mar 12, 2025

FWIW, been doing local testing using the following patch, this PR is now in a state where PublicIn still works.
But does change the lifetime of that struct. However mod_name is also an &'a str, so it is thankfully not a huge task to add that lifetime.

diff --git a/lrpar/examples/calc_actions/build.rs b/lrpar/examples/calc_actions/build.rs
index c441cb01..e40c6d3b 100644
--- a/lrpar/examples/calc_actions/build.rs
+++ b/lrpar/examples/calc_actions/build.rs
@@ -8,6 +8,7 @@ fn main() {
.rust_edition(lrlex::RustEdition::Rust2021)
.lrpar_config(|ctp| {
ctp.rust_edition(lrpar::RustEdition::Rust2021)

  •            .visibility(lrpar::Visibility::PublicIn("crate"))
               .grammar_in_src_dir("calc.y")
               .unwrap()
       })
    

@ratmice ratmice marked this pull request as ready for review March 12, 2025 10:34
@ratmice
Copy link
Collaborator Author

ratmice commented Mar 12, 2025

Just going to go ahead and unmark this as draft since the Visibility now works.
Still happy to change that back to VISIBILITY: &'static str (or anything else for that matter) though if that is preferred.

@ltratt
Copy link
Member

ltratt commented Mar 12, 2025

Please squash.

The quote crate doesn't deal with comments, since there isn't a
comment token.

This patch migrates the cache information to a module. The module
is nested within the `lrpar_mod!` module in order to avoid introducing
multiple modules with the same name at top-level when generating
multiple parsers.

When possible it generate constants, otherwise it generates
a function. Together these are intended to satisfy the same
purpose as the previous `CACHE INFORMATION` comment.
@ratmice ratmice force-pushed the refactor_lrpar_codegen_cache_info branch from 9cf906d to c5073e0 Compare March 12, 2025 12:01
@ratmice
Copy link
Collaborator Author

ratmice commented Mar 12, 2025

Squashed.

@ltratt ltratt added this pull request to the merge queue Mar 12, 2025
Merged via the queue into softdevteam:master with commit 139603a Mar 12, 2025
2 checks passed
@ratmice ratmice deleted the refactor_lrpar_codegen_cache_info branch March 12, 2025 13:02
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