Repository: pest-parser/pest (language: rust)

Issue:
Changes in grammar file not picked up by cargo for rebuild
This is probably not possible to solve within pest... it would require a build.rs-like API to add dependency files.

But maybe a hint in the documentation may make sense?


Discussion / hints:
If you stick a

```rust
const _GRAMMAR: &str = include_str!("your_grammar_file.pest");
```

in your source, then changes will be picked up.
Right. Then maybe this issue should be "stick `include_str!` into the derived code by default" :smile:
This should be the case in pest:2.0.2 already
Ah - it works indeed, but only in a debug build. Not in release...
Which is unsurprising, looking at https://github.com/pest-parser/pest/blob/master/generator/src/generator.rs#L162

Why is that restricted to `#[cfg(debug_assertions)]`? The constant will be optimized away anyway, no?

Fix patch:
diff --git a/generator/src/generator.rs b/generator/src/generator.rs
index e8345acc..0025ec95 100644
--- a/generator/src/generator.rs
+++ b/generator/src/generator.rs
@@ -154,12 +154,11 @@ fn generate_builtin_rules() -> HashMap<&'static str, TokenStream> {
     builtins
 }
 
-// Needed because Cargo doesn't watch for changes in grammers.
+// Needed because Cargo doesn't watch for changes in grammars.
 fn generate_include(name: &Ident, path: &str) -> TokenStream {
     let const_name = Ident::new(&format!("_PEST_GRAMMAR_{}", name), Span::call_site());
     quote! {
         #[allow(non_upper_case_globals)]
-        #[cfg(debug_assertions)]
         const #const_name: &'static str = include_str!(#path);
     }
 }
@@ -904,7 +903,6 @@ mod tests {
             generate(name, &generics, Path::new("test.pest"), rules, defaults, true).to_string(),
             quote! {
                 #[allow(non_upper_case_globals)]
-                #[cfg(debug_assertions)]
                 const _PEST_GRAMMAR_MyParser: &'static str = include_str!("test.pest");
 
                 #[allow(dead_code, non_camel_case_types)]


Test patch: