refactor(rust): misc fixes & tidying
This commit is contained in:
parent
5825e24d56
commit
abc7910381
23 changed files with 137 additions and 127 deletions
|
|
@ -298,7 +298,7 @@ impl<'a> ParseTableBuilder<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
reduction_info.precedence = precedence.clone();
|
||||
reduction_info.precedence.clone_from(precedence);
|
||||
if let Err(i) = reduction_info.symbols.binary_search(&symbol) {
|
||||
reduction_info.symbols.insert(i, symbol);
|
||||
}
|
||||
|
|
@ -604,13 +604,13 @@ impl<'a> ParseTableBuilder<'a> {
|
|||
write!(&mut msg, " {}", self.symbol_name(symbol)).unwrap();
|
||||
}
|
||||
|
||||
write!(
|
||||
writeln!(
|
||||
&mut msg,
|
||||
" • {} …\n\n",
|
||||
" • {} …\n",
|
||||
self.symbol_name(&conflicting_lookahead)
|
||||
)
|
||||
.unwrap();
|
||||
write!(&mut msg, "Possible interpretations:\n\n").unwrap();
|
||||
writeln!(&mut msg, "Possible interpretations:\n").unwrap();
|
||||
|
||||
let mut interpretations = conflicting_items
|
||||
.iter()
|
||||
|
|
@ -685,7 +685,7 @@ impl<'a> ParseTableBuilder<'a> {
|
|||
}
|
||||
|
||||
let mut resolution_count = 0;
|
||||
write!(&mut msg, "\nPossible resolutions:\n\n").unwrap();
|
||||
writeln!(&mut msg, "\nPossible resolutions:\n").unwrap();
|
||||
let mut shift_items = Vec::new();
|
||||
let mut reduce_items = Vec::new();
|
||||
for item in conflicting_items {
|
||||
|
|
@ -961,7 +961,7 @@ fn populate_following_tokens(
|
|||
for entry in result.iter_mut() {
|
||||
entry.insert(*extra);
|
||||
}
|
||||
result[extra.index] = all_tokens.clone();
|
||||
result[extra.index].clone_from(&all_tokens);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ impl<'a> ParseItem<'a> {
|
|||
|
||||
/// Create an item like this one, but advanced by one step.
|
||||
#[must_use]
|
||||
pub const fn successor(&self) -> ParseItem<'a> {
|
||||
pub const fn successor(&self) -> Self {
|
||||
ParseItem {
|
||||
variable_index: self.variable_index,
|
||||
production: self.production,
|
||||
|
|
|
|||
|
|
@ -166,19 +166,18 @@ fn parse_rule(json: RuleJSON) -> Rule {
|
|||
RuleJSON::PATTERN { value, flags } => Rule::Pattern(
|
||||
value,
|
||||
flags.map_or(String::new(), |f| {
|
||||
f.chars()
|
||||
.filter(|c| {
|
||||
if *c == 'i' {
|
||||
true
|
||||
} else {
|
||||
// silently ignore unicode flags
|
||||
if *c != 'u' && *c != 'v' {
|
||||
eprintln!("Warning: unsupported flag {c}");
|
||||
}
|
||||
false
|
||||
f.matches(|c| {
|
||||
if c == 'i' {
|
||||
true
|
||||
} else {
|
||||
// silently ignore unicode flags
|
||||
if c != 'u' && c != 'v' {
|
||||
eprintln!("Warning: unsupported flag {c}");
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
false
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}),
|
||||
),
|
||||
RuleJSON::SYMBOL { name } => Rule::NamedSymbol(name),
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ impl InlinedProductionMapBuilder {
|
|||
self.productions
|
||||
.iter()
|
||||
.position(|p| *p == production)
|
||||
.unwrap_or({
|
||||
.unwrap_or_else(|| {
|
||||
self.productions.push(production);
|
||||
self.productions.len() - 1
|
||||
})
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ macro_rules! add {
|
|||
}
|
||||
|
||||
macro_rules! add_whitespace {
|
||||
($this: tt) => {{
|
||||
($this:tt) => {{
|
||||
for _ in 0..$this.indent_level {
|
||||
write!(&mut $this.buffer, " ").unwrap();
|
||||
}
|
||||
|
|
@ -45,13 +45,13 @@ macro_rules! add_line {
|
|||
}
|
||||
|
||||
macro_rules! indent {
|
||||
($this: tt) => {
|
||||
($this:tt) => {
|
||||
$this.indent_level += 1;
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! dedent {
|
||||
($this: tt) => {
|
||||
($this:tt) => {
|
||||
assert_ne!($this.indent_level, 0);
|
||||
$this.indent_level -= 1;
|
||||
};
|
||||
|
|
@ -221,9 +221,8 @@ impl Generator {
|
|||
});
|
||||
|
||||
// Some aliases match an existing symbol in the grammar.
|
||||
let alias_id;
|
||||
if let Some(existing_symbol) = existing_symbol {
|
||||
alias_id = self.symbol_ids[&self.symbol_map[&existing_symbol]].clone();
|
||||
let alias_id = if let Some(existing_symbol) = existing_symbol {
|
||||
self.symbol_ids[&self.symbol_map[&existing_symbol]].clone()
|
||||
}
|
||||
// Other aliases don't match any existing symbol, and need their own
|
||||
// identifiers.
|
||||
|
|
@ -232,12 +231,12 @@ impl Generator {
|
|||
self.unique_aliases.insert(i, alias.clone());
|
||||
}
|
||||
|
||||
alias_id = if alias.is_named {
|
||||
if alias.is_named {
|
||||
format!("alias_sym_{}", self.sanitize_identifier(&alias.value))
|
||||
} else {
|
||||
format!("anon_alias_sym_{}", self.sanitize_identifier(&alias.value))
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
self.alias_ids.entry(alias.clone()).or_insert(alias_id);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue