@@ -599,13 +599,8 @@ where
599599 if FileTime :: from_last_modification_time ( out_rs_md)
600600 > FileTime :: from_last_modification_time ( inmd)
601601 {
602- if let Ok ( mut outc) = read_to_string ( outp) {
603- // Strip whitespace from the output file and the cache since the copy of
604- // the cache in the output file may be affected by pretty printing.
605- let mut cache = cache. to_string ( ) ;
606- outc. retain ( |c| !c. is_whitespace ( ) ) ;
607- cache. retain ( |c| !c. is_whitespace ( ) ) ;
608- if outc. contains ( & cache) {
602+ if let Ok ( outc) = read_to_string ( outp) {
603+ if outc. contains ( & cache. to_string ( ) ) {
609604 return Ok ( CTParser {
610605 regenerated : false ,
611606 rule_ids,
@@ -614,6 +609,8 @@ where
614609 } else {
615610 #[ cfg( grmtools_extra_checks) ]
616611 if std:: env:: var ( "CACHE_EXPECTED" ) . is_ok ( ) {
612+ eprintln ! ( "outc: {}" , outc) ;
613+ eprintln ! ( "using cache: {}" , cache, ) ;
617614 // Primarily for use in the testsuite.
618615 panic ! ( "The cache regenerated however, it was expected to match" ) ;
619616 }
@@ -644,7 +641,14 @@ where
644641 }
645642 }
646643
647- self . output_file ( & grm, & stable, & derived_mod_name, outp, & cache) ?;
644+ self . output_file ( & grm, & stable, & derived_mod_name, outp, & quote ! {
645+ // This declaration can be affected by the pretty printer.
646+ // But we would hope the actual cache string is not.
647+ //
648+ // This is emitted for the purposes of performing the cache check.
649+ // on the output source, but is not used by generated parser.
650+ const _: & str = #cache;
651+ } ) ?;
648652 let conflicts = if stable. conflicts ( ) . is_some ( ) {
649653 Some ( ( grm, sgraph, stable) )
650654 } else {
@@ -862,31 +866,22 @@ where
862866 ) )
863867 } )
864868 . collect :: < Vec < _ > > ( ) ;
865- let rule_map_len = rule_map. len ( ) ;
866- quote ! {
867- #[ allow( unused) ]
868- mod _cache_information_ {
869- use :: lrpar:: { RecoveryKind , Visibility , RustEdition } ;
870- use :: cfgrammar:: yacc:: YaccKind ;
871-
872- const BUILD_TIME : & str = #build_time;
873- // May differ from `MOD_NAME` by being derived from the grammar path.
874- const DERIVED_MOD_NAME : & str = #derived_mod_name;
875- const GRAMMAR_PATH : & str = #grammar_path;
876- // As explicitly set by the builder.
877- const MOD_NAME : Option <& str > = #mod_name;
878- const RECOVERER : RecoveryKind = #recoverer;
879- const YACC_KIND : YaccKind = #yacckind;
880- const ERROR_ON_CONFLICTS : bool = #error_on_conflicts;
881- const SHOW_WARNINGS : bool = #show_warnings;
882- const WARNINGS_ARE_ERRORS : bool = #warnings_are_errors;
883- const RUST_EDITION : RustEdition = #rust_edition;
884- const RULE_IDS_MAP : [ ( usize , & str ) ; #rule_map_len] = [ #( #rule_map, ) * ] ;
885- fn visibility( ) -> Visibility {
886- #visibility
887- }
888- }
889- }
869+ let cache_info = quote ! {
870+ BUILD_TIME = #build_time
871+ DERIVED_MOD_NAME = #derived_mod_name
872+ GRAMMAR_PATH = #grammar_path
873+ MOD_NAME = #mod_name
874+ RECOVERER = #recoverer
875+ YACC_KIND = #yacckind
876+ ERROR_ON_CONFLICTS = #error_on_conflicts
877+ SHOW_WARNINGS = #show_warnings
878+ WARNINGS_ARE_ERRORS = #warnings_are_errors
879+ RUST_EDITION = #rust_edition
880+ RULE_IDS_MAP = [ #( #rule_map, ) * ]
881+ VISIBILITY = #visibility
882+ } ;
883+ let cache_info_str = cache_info. to_string ( ) ;
884+ quote ! ( #cache_info_str)
890885 }
891886
892887 /// Generate the main parse() function for the output file.
0 commit comments