Skip to content

Commit c0097a5

Browse files
committed
Sort tokens in lexer builder as well
1 parent 719da09 commit c0097a5

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lrlex/src/lib/ctbuilder.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,9 @@ where
782782

783783
let mut token_consts = TokenStream::new();
784784
if let Some(rim) = self.rule_ids_map {
785-
for (name, id) in rim {
785+
let mut rim_sorted = Vec::from_iter(rim.iter());
786+
rim_sorted.sort_by_key(|(k, _)| *k);
787+
for (name, id) in rim_sorted {
786788
if RE_TOKEN_ID.is_match(&name) {
787789
let tok_ident = format_ident!("N_{}", name.to_ascii_uppercase());
788790
let storaget =
@@ -815,9 +817,15 @@ where
815817
};
816818
// Try and run a code formatter on the generated code.
817819
let unformatted = out_tokens.to_string();
818-
let outs = syn::parse_str(&unformatted)
820+
let mut outs = String::new();
821+
// Record the time that this version of lrlex was built. If the source code changes and rustc
822+
// forces a recompile, this will change this value, causing anything which depends on this
823+
// build of lrlex to be recompiled too.
824+
let timestamp = env!("VERGEN_BUILD_TIMESTAMP");
825+
write!(outs, "// lrlex build time: {}\n\n", quote!(#timestamp),).ok();
826+
outs.push_str(&syn::parse_str(&unformatted)
819827
.map(|syntax_tree| prettyplease::unparse(&syntax_tree))
820-
.unwrap_or(unformatted);
828+
.unwrap_or(unformatted));
821829
// If the file we're about to write out already exists with the same contents, then we
822830
// don't overwrite it (since that will force a recompile of the file, and relinking of the
823831
// binary etc).

0 commit comments

Comments
 (0)