@@ -676,12 +676,19 @@ where
676676 ) -> Result < ( ) , Box < dyn Error > > {
677677 let mut outs = String :: new ( ) ;
678678 writeln ! ( outs, "{} mod {} {{" , self . visibility. cow_str( ) , mod_name) . ok ( ) ;
679+ // Emit user program section, and actions at the top so they may specify inner attributes.
680+ if let Some ( YaccKind :: Original ( YaccOriginalActionKind :: UserAction ) | YaccKind :: Grmtools ) =
681+ self . yacckind
682+ {
683+ outs. push_str ( & self . gen_user_actions ( grm) ) ;
684+ }
685+ outs. push_str ( " mod _parser_ {\n " ) ;
679686 outs. push_str (
680- " #![allow(clippy::type_complexity)]
681- #![allow(clippy::unnecessary_wraps)]
682- #![deny(unsafe_code)]
683- #[allow(unused_imports)]
684- use ::lrpar::Lexeme ;
687+ " #![allow(clippy::type_complexity)]
688+ #![allow(clippy::unnecessary_wraps)]
689+ #![deny(unsafe_code)]
690+ #[allow(unused_imports)]
691+ use super::* ;
685692" ,
686693 ) ;
687694
@@ -691,13 +698,17 @@ where
691698 match self . yacckind . unwrap ( ) {
692699 YaccKind :: Original ( YaccOriginalActionKind :: UserAction ) | YaccKind :: Grmtools => {
693700 outs. push_str ( & self . gen_wrappers ( grm) ) ;
694- outs. push_str ( & self . gen_user_actions ( grm) ) ;
695701 }
696702 YaccKind :: Original ( YaccOriginalActionKind :: NoAction )
697703 | YaccKind :: Original ( YaccOriginalActionKind :: GenericParseTree ) => ( ) ,
698704 _ => unreachable ! ( ) ,
699705 }
700- outs. push_str ( "}\n \n " ) ;
706+ outs. push_str ( " } // End of `mod _parser_`\n \n " ) ;
707+ outs. push_str ( " #[allow(unused_imports)]\n " ) ;
708+ outs. push_str ( " pub use _parser_::*;\n " ) ;
709+ outs. push_str ( " #[allow(unused_imports)]\n " ) ;
710+ outs. push_str ( " use ::lrpar::Lexeme;\n " ) ;
711+ outs. push_str ( "} // End of `mod {mod_name}` \n \n " ) ;
701712
702713 // Output the cache so that we can check whether the IDs map is stable.
703714 outs. push_str ( cache) ;
@@ -1103,6 +1114,7 @@ where
11031114 if let Some ( s) = grm. programs ( ) {
11041115 outs. push_str ( "\n // User code from the program section\n \n " ) ;
11051116 outs. push_str ( s) ;
1117+ outs. push_str ( "\n // End of user code from the program section\n \n " ) ;
11061118 }
11071119
11081120 // Convert actions to functions
@@ -1144,7 +1156,6 @@ where
11441156 outs,
11451157 " // {rulename}
11461158 #[allow(clippy::too_many_arguments)]
1147- #[allow(unsafe_code)] // Allow an action to embed unsafe blocks within it.
11481159 fn {prefix}action_{}<'lexer, 'input: 'lexer>({prefix}ridx: ::cfgrammar::RIdx<{storaget}>,
11491160 {prefix}lexer: &'lexer dyn ::lrpar::NonStreamingLexer<'input, {lexertypest}>,
11501161 {prefix}span: ::cfgrammar::Span,
0 commit comments