chore: a few minor lints
* do not use `&` for the format args as it cannot (yet) be optimized by the compiler * a few format inlining
This commit is contained in:
parent
c8353a52af
commit
9dbe165296
11 changed files with 32 additions and 36 deletions
|
|
@ -93,9 +93,9 @@ impl Config {
|
|||
};
|
||||
|
||||
let content = fs::read_to_string(&location)
|
||||
.with_context(|| format!("Failed to read {}", &location.to_string_lossy()))?;
|
||||
.with_context(|| format!("Failed to read {}", location.to_string_lossy()))?;
|
||||
let config = serde_json::from_str(&content)
|
||||
.with_context(|| format!("Bad JSON config {}", &location.to_string_lossy()))?;
|
||||
.with_context(|| format!("Bad JSON config {}", location.to_string_lossy()))?;
|
||||
Ok(Self { location, config })
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -177,8 +177,7 @@ impl<'a> LexTableBuilder<'a> {
|
|||
|
||||
if is_new {
|
||||
info!(
|
||||
"entry point state: {}, tokens: {:?}",
|
||||
state_id,
|
||||
"entry point state: {state_id}, tokens: {:?}",
|
||||
tokens
|
||||
.iter()
|
||||
.map(|t| &self.lexical_grammar.variables[t.index].name)
|
||||
|
|
|
|||
|
|
@ -1113,7 +1113,7 @@ impl<'a> ParseTableBuilder<'a> {
|
|||
if variable.kind == VariableType::Named {
|
||||
variable.name.clone()
|
||||
} else {
|
||||
format!("'{}'", &variable.name)
|
||||
format!("'{}'", variable.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -192,7 +192,7 @@ impl fmt::Display for ParseItemDisplay<'_> {
|
|||
write!(
|
||||
f,
|
||||
"{} →",
|
||||
&self.1.variables[self.0.variable_index as usize].name
|
||||
self.1.variables[self.0.variable_index as usize].name
|
||||
)?;
|
||||
}
|
||||
|
||||
|
|
@ -220,14 +220,14 @@ impl fmt::Display for ParseItemDisplay<'_> {
|
|||
write!(f, " ")?;
|
||||
if step.symbol.is_terminal() {
|
||||
if let Some(variable) = self.2.variables.get(step.symbol.index) {
|
||||
write!(f, "{}", &variable.name)?;
|
||||
write!(f, "{}", variable.name)?;
|
||||
} else {
|
||||
write!(f, "terminal-{}", step.symbol.index)?;
|
||||
}
|
||||
} else if step.symbol.is_external() {
|
||||
write!(f, "{}", &self.1.external_tokens[step.symbol.index].name)?;
|
||||
write!(f, "{}", self.1.external_tokens[step.symbol.index].name)?;
|
||||
} else {
|
||||
write!(f, "{}", &self.1.variables[step.symbol.index].name)?;
|
||||
write!(f, "{}", self.1.variables[step.symbol.index].name)?;
|
||||
}
|
||||
|
||||
if let Some(alias) = &step.alias {
|
||||
|
|
@ -295,9 +295,9 @@ impl fmt::Display for TokenSetDisplay<'_> {
|
|||
write!(f, "terminal-{}", symbol.index)?;
|
||||
}
|
||||
} else if symbol.is_external() {
|
||||
write!(f, "{}", &self.1.external_tokens[symbol.index].name)?;
|
||||
write!(f, "{}", self.1.external_tokens[symbol.index].name)?;
|
||||
} else {
|
||||
write!(f, "{}", &self.1.variables[symbol.index].name)?;
|
||||
write!(f, "{}", self.1.variables[symbol.index].name)?;
|
||||
}
|
||||
}
|
||||
write!(f, "]")?;
|
||||
|
|
|
|||
|
|
@ -525,7 +525,7 @@ fn report_state_info<'a>(
|
|||
}
|
||||
eprintln!(
|
||||
"\nitems:\n{}",
|
||||
self::item::ParseItemSetDisplay(item_set, syntax_grammar, lexical_grammar,),
|
||||
item::ParseItemSetDisplay(item_set, syntax_grammar, lexical_grammar),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -949,20 +949,19 @@ mod tests {
|
|||
assert_eq!(
|
||||
left.remove_intersection(&mut right),
|
||||
row.intersection,
|
||||
"row {}a: {:?} && {:?}",
|
||||
i,
|
||||
"row {i}a: {:?} && {:?}",
|
||||
row.left,
|
||||
row.right
|
||||
);
|
||||
assert_eq!(
|
||||
left, row.left_only,
|
||||
"row {}a: {:?} - {:?}",
|
||||
i, row.left, row.right
|
||||
"row {i}a: {:?} - {:?}",
|
||||
row.left, row.right
|
||||
);
|
||||
assert_eq!(
|
||||
right, row.right_only,
|
||||
"row {}a: {:?} - {:?}",
|
||||
i, row.right, row.left
|
||||
"row {i}a: {:?} - {:?}",
|
||||
row.right, row.left
|
||||
);
|
||||
|
||||
let mut left = row.left.clone();
|
||||
|
|
@ -970,27 +969,25 @@ mod tests {
|
|||
assert_eq!(
|
||||
right.remove_intersection(&mut left),
|
||||
row.intersection,
|
||||
"row {}b: {:?} && {:?}",
|
||||
i,
|
||||
"row {i}b: {:?} && {:?}",
|
||||
row.left,
|
||||
row.right
|
||||
);
|
||||
assert_eq!(
|
||||
left, row.left_only,
|
||||
"row {}b: {:?} - {:?}",
|
||||
i, row.left, row.right
|
||||
"row {i}b: {:?} - {:?}",
|
||||
row.left, row.right
|
||||
);
|
||||
assert_eq!(
|
||||
right, row.right_only,
|
||||
"row {}b: {:?} - {:?}",
|
||||
i, row.right, row.left
|
||||
"row {i}b: {:?} - {:?}",
|
||||
row.right, row.left
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
row.left.clone().difference(row.right.clone()),
|
||||
row.left_only,
|
||||
"row {}b: {:?} -- {:?}",
|
||||
i,
|
||||
"row {i}b: {:?} -- {:?}",
|
||||
row.left,
|
||||
row.right
|
||||
);
|
||||
|
|
|
|||
|
|
@ -322,7 +322,7 @@ impl TokenExtractor {
|
|||
Variable {
|
||||
name: format!(
|
||||
"{}_token{}",
|
||||
&self.current_variable_name, self.current_variable_token_count
|
||||
self.current_variable_name, self.current_variable_token_count
|
||||
),
|
||||
kind: VariableType::Auxiliary,
|
||||
rule: rule.clone(),
|
||||
|
|
|
|||
|
|
@ -387,7 +387,7 @@ impl Generator {
|
|||
self.parse_table.symbols.len()
|
||||
);
|
||||
add_line!(self, "#define ALIAS_COUNT {}", self.unique_aliases.len());
|
||||
add_line!(self, "#define TOKEN_COUNT {}", token_count);
|
||||
add_line!(self, "#define TOKEN_COUNT {token_count}");
|
||||
add_line!(
|
||||
self,
|
||||
"#define EXTERNAL_TOKEN_COUNT {}",
|
||||
|
|
@ -991,7 +991,7 @@ impl Generator {
|
|||
add!(
|
||||
self,
|
||||
"set_contains({}, {}, lookahead)",
|
||||
&char_set_info.constant_name,
|
||||
char_set_info.constant_name,
|
||||
large_set.range_count(),
|
||||
);
|
||||
if check_eof {
|
||||
|
|
@ -1150,7 +1150,7 @@ impl Generator {
|
|||
indent!(self);
|
||||
for (i, state) in self.parse_table.states.iter().enumerate() {
|
||||
add_whitespace!(self);
|
||||
add!(self, "[{}] = {{", i);
|
||||
add!(self, "[{i}] = {{");
|
||||
if state.is_end_of_non_terminal_extra() {
|
||||
add!(self, "(TSStateId)(-1),");
|
||||
} else {
|
||||
|
|
@ -1190,7 +1190,7 @@ impl Generator {
|
|||
if id == 0 {
|
||||
continue;
|
||||
}
|
||||
add_line!(self, "[{}] = {{", id);
|
||||
add_line!(self, "[{id}] = {{");
|
||||
indent!(self);
|
||||
for token in set.iter() {
|
||||
add_line!(self, "{},", self.symbol_ids[&token]);
|
||||
|
|
@ -1250,7 +1250,7 @@ impl Generator {
|
|||
indent!(self);
|
||||
for i in 0..self.parse_table.external_lex_states.len() {
|
||||
if !self.parse_table.external_lex_states[i].is_empty() {
|
||||
add_line!(self, "[{}] = {{", i);
|
||||
add_line!(self, "[{i}] = {{");
|
||||
indent!(self);
|
||||
for token in self.parse_table.external_lex_states[i].iter() {
|
||||
add_line!(
|
||||
|
|
|
|||
|
|
@ -1342,7 +1342,7 @@ impl Loader {
|
|||
.with_context(|| {
|
||||
format!(
|
||||
"Failed to load language for file name {}",
|
||||
&path.file_name().unwrap().to_string_lossy()
|
||||
path.file_name().unwrap().to_string_lossy()
|
||||
)
|
||||
})?
|
||||
{
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ pub fn test_tags_indented(
|
|||
})?;
|
||||
let tags_config = language_config
|
||||
.tags_config(language)?
|
||||
.ok_or_else(|| anyhow!("No tags config found for {:?}", test_file_path))?;
|
||||
.ok_or_else(|| anyhow!("No tags config found for {test_file_path:?}"))?;
|
||||
match test_tag(
|
||||
tags_context,
|
||||
tags_config,
|
||||
|
|
|
|||
|
|
@ -95,10 +95,10 @@ let highlights = highlighter.highlight(
|
|||
for event in highlights {
|
||||
match event.unwrap() {
|
||||
HighlightEvent::Source {start, end} => {
|
||||
eprintln!("source: {}-{}", start, end);
|
||||
eprintln!("source: {start}-{end}");
|
||||
},
|
||||
HighlightEvent::HighlightStart(s) => {
|
||||
eprintln!("highlight style started: {:?}", s);
|
||||
eprintln!("highlight style started: {s:?}");
|
||||
},
|
||||
HighlightEvent::HighlightEnd => {
|
||||
eprintln!("highlight style ended");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue