Skip to content

Commit

Permalink
chore: thanks cargo clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Devin-Yeung committed Nov 22, 2023
1 parent 79137fb commit a736f68
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 20 deletions.
11 changes: 3 additions & 8 deletions src/slr/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::utils::follow::Follow;
use bnf::{Grammar, Production, Term};
use std::cell::RefCell;
use std::collections::HashMap;
use std::fmt::{format, Display, Formatter};
use std::fmt::{Display, Formatter};
use std::iter::{once, repeat};
use tabled::builder::Builder;
use tabled::Table;
Expand Down Expand Up @@ -91,17 +91,12 @@ impl<'grammar> SLRTableBuilder<'grammar> {
}

fn reduce(&self, index: usize, lr0: &LR0Item) {
let grammar_index = self.grammar.get_index_of(&lr0.rhs).unwrap();
let grammar_index = self.grammar.get_index_of(lr0.rhs).unwrap();
let prod = self.grammar.get(lr0.rhs).unwrap();
let mut table = self.table.borrow_mut();
for term in self.follow.follow_of(&prod.lhs).collect::<Vec<_>>() {
table[index].insert(term, SLRInstruction::Reduce(grammar_index));
println!(
"Reduce: set (I_{}, {}) = r{}",
index,
term.to_string(),
grammar_index
);
println!("Reduce: set (I_{}, {}) = r{}", index, term, grammar_index);
}
}

Expand Down
8 changes: 3 additions & 5 deletions src/slr/core.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::fmt::{Display, Formatter};

#[derive(Clone)]
pub enum SLRInstruction {
Reduce(usize),
Expand All @@ -19,8 +17,8 @@ impl ToString for SLRInstruction {
}
}

impl Into<String> for &SLRInstruction {
fn into(self) -> String {
self.to_string()
impl From<&SLRInstruction> for String {
fn from(val: &SLRInstruction) -> Self {
val.to_string()
}
}
2 changes: 0 additions & 2 deletions src/utils/first/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ impl<'grammar> FirstBuilder<'grammar> {

// initialize the table
symbols(grammar)
.into_iter()
.filter(|term| term != &epsilon()) // epsilon is a special non-terminal
.for_each(|term| {
first.insert(term, HashSet::new());
Expand All @@ -38,7 +37,6 @@ impl<'grammar> FirstBuilder<'grammar> {

fn build_first(&mut self) {
symbols(self.grammar)
.into_iter()
.filter(|term| term != &epsilon())
.for_each(|t| {
match t {
Expand Down
1 change: 0 additions & 1 deletion src/utils/follow/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ impl<'grammar> FollowBuilder<'grammar> {

// initialize the table
symbols(grammar)
.into_iter()
.filter(|term| term != &epsilon()) // epsilon is a special non-terminal
.for_each(|term| {
follow.insert(term, HashSet::new());
Expand Down
6 changes: 2 additions & 4 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ pub fn symbols(grammar: &Grammar) -> impl Iterator<Item = &Term> {
}

pub fn terminals(grammar: &Grammar) -> impl Iterator<Item = &Term> {
symbols(&grammar)
.into_iter()
symbols(grammar)
.filter(|term| term != &epsilon())
.filter(|term| matches!(*term, Term::Terminal(_)))
}

pub fn nonterminals(grammar: &Grammar) -> impl Iterator<Item = &Term> {
symbols(&grammar)
.into_iter()
symbols(grammar)
.filter(|term| term != &epsilon())
.filter(|term| matches!(*term, Term::Nonterminal(_)))
}
Expand Down

0 comments on commit a736f68

Please sign in to comment.