fix some clippy lint warnings
This commit is contained in:
@@ -197,8 +197,8 @@ impl RegType {
|
|||||||
impl fmt::Display for RegType {
|
impl fmt::Display for RegType {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
&RegType::Perm(val) => write!(f, "Y{}", val),
|
RegType::Perm(val) => write!(f, "Y{}", val),
|
||||||
&RegType::Temp(val) => write!(f, "X{}", val),
|
RegType::Temp(val) => write!(f, "X{}", val),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -220,10 +220,10 @@ impl VarReg {
|
|||||||
impl fmt::Display for VarReg {
|
impl fmt::Display for VarReg {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
&VarReg::Norm(RegType::Perm(reg)) => write!(f, "Y{}", reg),
|
VarReg::Norm(RegType::Perm(reg)) => write!(f, "Y{}", reg),
|
||||||
&VarReg::Norm(RegType::Temp(reg)) => write!(f, "X{}", reg),
|
VarReg::Norm(RegType::Temp(reg)) => write!(f, "X{}", reg),
|
||||||
&VarReg::ArgAndNorm(RegType::Perm(reg), arg) => write!(f, "Y{} A{}", reg, arg),
|
VarReg::ArgAndNorm(RegType::Perm(reg), arg) => write!(f, "Y{} A{}", reg, arg),
|
||||||
&VarReg::ArgAndNorm(RegType::Temp(reg), arg) => write!(f, "X{} A{}", reg, arg),
|
VarReg::ArgAndNorm(RegType::Temp(reg), arg) => write!(f, "X{} A{}", reg, arg),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -382,16 +382,16 @@ impl ParserError {
|
|||||||
|
|
||||||
pub fn as_str(&self) -> &'static str {
|
pub fn as_str(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
&ParserError::BackQuotedString(..) => "back_quoted_string",
|
ParserError::BackQuotedString(..) => "back_quoted_string",
|
||||||
&ParserError::UnexpectedChar(..) => "unexpected_char",
|
ParserError::UnexpectedChar(..) => "unexpected_char",
|
||||||
&ParserError::UnexpectedEOF => "unexpected_end_of_file",
|
ParserError::UnexpectedEOF => "unexpected_end_of_file",
|
||||||
&ParserError::IncompleteReduction(..) => "incomplete_reduction",
|
ParserError::IncompleteReduction(..) => "incomplete_reduction",
|
||||||
&ParserError::InvalidSingleQuotedCharacter(..) => "invalid_single_quoted_character",
|
ParserError::InvalidSingleQuotedCharacter(..) => "invalid_single_quoted_character",
|
||||||
&ParserError::IO(_) => "input_output_error",
|
ParserError::IO(_) => "input_output_error",
|
||||||
&ParserError::MissingQuote(..) => "missing_quote",
|
ParserError::MissingQuote(..) => "missing_quote",
|
||||||
&ParserError::NonPrologChar(..) => "non_prolog_character",
|
ParserError::NonPrologChar(..) => "non_prolog_character",
|
||||||
&ParserError::ParseBigInt(..) => "cannot_parse_big_int",
|
ParserError::ParseBigInt(..) => "cannot_parse_big_int",
|
||||||
&ParserError::Utf8Error(..) => "utf8_conversion_error",
|
ParserError::Utf8Error(..) => "utf8_conversion_error",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -525,21 +525,21 @@ pub enum Constant {
|
|||||||
impl fmt::Display for Constant {
|
impl fmt::Display for Constant {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
&Constant::Atom(ref atom, _) => {
|
Constant::Atom(ref atom, _) => {
|
||||||
if atom.as_str().chars().any(|c| "`.$'\" ".contains(c)) {
|
if atom.as_str().chars().any(|c| "`.$'\" ".contains(c)) {
|
||||||
write!(f, "'{}'", atom.as_str())
|
write!(f, "'{}'", atom.as_str())
|
||||||
} else {
|
} else {
|
||||||
write!(f, "{}", atom.as_str())
|
write!(f, "{}", atom.as_str())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&Constant::Char(c) => write!(f, "'{}'", c as u32),
|
Constant::Char(c) => write!(f, "'{}'", *c as u32),
|
||||||
&Constant::EmptyList => write!(f, "[]"),
|
Constant::EmptyList => write!(f, "[]"),
|
||||||
&Constant::Fixnum(n) => write!(f, "{}", n),
|
Constant::Fixnum(n) => write!(f, "{}", n),
|
||||||
&Constant::Integer(ref n) => write!(f, "{}", n),
|
Constant::Integer(ref n) => write!(f, "{}", n),
|
||||||
&Constant::Rational(ref n) => write!(f, "{}", n),
|
Constant::Rational(ref n) => write!(f, "{}", n),
|
||||||
&Constant::Float(ref n) => write!(f, "{}", n),
|
Constant::Float(ref n) => write!(f, "{}", n),
|
||||||
&Constant::String(ref s) => write!(f, "\"{}\"", &s),
|
Constant::String(ref s) => write!(f, "\"{}\"", &s),
|
||||||
&Constant::Usize(integer) => write!(f, "u{}", integer),
|
Constant::Usize(integer) => write!(f, "u{}", integer),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -549,7 +549,7 @@ impl PartialEq for Constant {
|
|||||||
match (self, other) {
|
match (self, other) {
|
||||||
(&Constant::Atom(ref atom, _), &Constant::Char(c))
|
(&Constant::Atom(ref atom, _), &Constant::Char(c))
|
||||||
| (&Constant::Char(c), &Constant::Atom(ref atom, _)) => {
|
| (&Constant::Char(c), &Constant::Atom(ref atom, _)) => {
|
||||||
atom.is_char() && Some(c) == atom.as_str().chars().next()
|
atom.is_char() && atom.as_str().starts_with(c)
|
||||||
}
|
}
|
||||||
(&Constant::Atom(ref a1, _), &Constant::Atom(ref a2, _)) => a1.as_str() == a2.as_str(),
|
(&Constant::Atom(ref a1, _), &Constant::Atom(ref a2, _)) => a1.as_str() == a2.as_str(),
|
||||||
(&Constant::Char(c1), &Constant::Char(c2)) => c1 == c2,
|
(&Constant::Char(c1), &Constant::Char(c2)) => c1 == c2,
|
||||||
@@ -565,7 +565,7 @@ impl PartialEq for Constant {
|
|||||||
(&Constant::Integer(ref n1), &Constant::Integer(ref n2)) => n1 == n2,
|
(&Constant::Integer(ref n1), &Constant::Integer(ref n2)) => n1 == n2,
|
||||||
(&Constant::Rational(ref n1), &Constant::Rational(ref n2)) => n1 == n2,
|
(&Constant::Rational(ref n1), &Constant::Rational(ref n2)) => n1 == n2,
|
||||||
(&Constant::Float(ref n1), &Constant::Float(ref n2)) => n1 == n2,
|
(&Constant::Float(ref n1), &Constant::Float(ref n2)) => n1 == n2,
|
||||||
(&Constant::String(ref s1), &Constant::String(ref s2)) => &s1 == &s2,
|
(&Constant::String(ref s1), &Constant::String(ref s2)) => s1 == s2,
|
||||||
(&Constant::EmptyList, &Constant::EmptyList) => true,
|
(&Constant::EmptyList, &Constant::EmptyList) => true,
|
||||||
(&Constant::Usize(u1), &Constant::Usize(u2)) => u1 == u2,
|
(&Constant::Usize(u1), &Constant::Usize(u2)) => u1 == u2,
|
||||||
_ => false,
|
_ => false,
|
||||||
@@ -632,7 +632,7 @@ impl ClauseName {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn owning_module(&self) -> Self {
|
pub fn owning_module(&self) -> Self {
|
||||||
match self {
|
match self {
|
||||||
&ClauseName::User(ref name) => {
|
ClauseName::User(ref name) => {
|
||||||
let module = name.owning_module();
|
let module = name.owning_module();
|
||||||
ClauseName::User(TabledRc {
|
ClauseName::User(TabledRc {
|
||||||
atom: module.clone(),
|
atom: module.clone(),
|
||||||
@@ -646,8 +646,8 @@ impl ClauseName {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_rc(&self) -> Rc<String> {
|
pub fn to_rc(&self) -> Rc<String> {
|
||||||
match self {
|
match self {
|
||||||
&ClauseName::BuiltIn(s) => Rc::new(s.to_string()),
|
ClauseName::BuiltIn(s) => Rc::new(s.to_string()),
|
||||||
&ClauseName::User(ref rc) => rc.inner(),
|
ClauseName::User(ref rc) => rc.inner(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -687,14 +687,14 @@ impl ClauseName {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn as_str(&self) -> &str {
|
pub fn as_str(&self) -> &str {
|
||||||
match self {
|
match self {
|
||||||
&ClauseName::BuiltIn(s) => s,
|
ClauseName::BuiltIn(s) => s,
|
||||||
&ClauseName::User(ref name) => name.as_ref(),
|
ClauseName::User(ref name) => name.as_ref(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_char(&self) -> bool {
|
pub fn is_char(&self) -> bool {
|
||||||
!self.as_str().is_empty() && self.as_str().chars().skip(1).next().is_none()
|
!self.as_str().is_empty() && self.as_str().chars().nth(1).is_none()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn defrock_brackets(self) -> Self {
|
pub fn defrock_brackets(self) -> Self {
|
||||||
@@ -739,8 +739,8 @@ pub enum Term {
|
|||||||
impl Term {
|
impl Term {
|
||||||
pub fn shared_op_desc(&self) -> Option<SharedOpDesc> {
|
pub fn shared_op_desc(&self) -> Option<SharedOpDesc> {
|
||||||
match self {
|
match self {
|
||||||
&Term::Clause(_, _, _, ref spec) => spec.clone(),
|
Term::Clause(_, _, _, ref spec) => spec.clone(),
|
||||||
&Term::Constant(_, Constant::Atom(_, ref spec)) => spec.clone(),
|
Term::Constant(_, Constant::Atom(_, ref spec)) => spec.clone(),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -754,7 +754,7 @@ impl Term {
|
|||||||
|
|
||||||
pub fn first_arg(&self) -> Option<&Term> {
|
pub fn first_arg(&self) -> Option<&Term> {
|
||||||
match self {
|
match self {
|
||||||
&Term::Clause(_, _, ref terms, _) => terms.first().map(|bt| bt.as_ref()),
|
Term::Clause(_, _, ref terms, _) => terms.first().map(|bt| bt.as_ref()),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -780,14 +780,14 @@ impl Term {
|
|||||||
|
|
||||||
pub fn arity(&self) -> usize {
|
pub fn arity(&self) -> usize {
|
||||||
match self {
|
match self {
|
||||||
&Term::Clause(_, _, ref child_terms, ..) => child_terms.len(),
|
Term::Clause(_, _, ref child_terms, ..) => child_terms.len(),
|
||||||
_ => 0,
|
_ => 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unfold_by_str_once(term: &mut Term, s: &str) -> Option<(Term, Term)> {
|
fn unfold_by_str_once(term: &mut Term, s: &str) -> Option<(Term, Term)> {
|
||||||
if let &mut Term::Clause(_, ref name, ref mut subterms, _) = term {
|
if let Term::Clause(_, ref name, ref mut subterms, _) = term {
|
||||||
if name.as_str() == s && subterms.len() == 2 {
|
if name.as_str() == s && subterms.len() == 2 {
|
||||||
let snd = *subterms.pop().unwrap();
|
let snd = *subterms.pop().unwrap();
|
||||||
let fst = *subterms.pop().unwrap();
|
let fst = *subterms.pop().unwrap();
|
||||||
|
|||||||
@@ -517,7 +517,7 @@ impl<'a, R: Read> Lexer<'a, R> {
|
|||||||
if single_quote_char!(self.lookahead_char()?) {
|
if single_quote_char!(self.lookahead_char()?) {
|
||||||
self.skip_char()?;
|
self.skip_char()?;
|
||||||
|
|
||||||
if !token.is_empty() && token.chars().skip(1).next().is_none() {
|
if !token.is_empty() && token.chars().nth(1).is_none() {
|
||||||
if let Some(c) = token.chars().next() {
|
if let Some(c) = token.chars().next() {
|
||||||
return Ok(Token::Constant(Constant::Char(c)));
|
return Ok(Token::Constant(Constant::Char(c)));
|
||||||
}
|
}
|
||||||
@@ -713,7 +713,7 @@ impl<'a, R: Read> Lexer<'a, R> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.get_single_quoted_char()
|
self.get_single_quoted_char()
|
||||||
.and_then(|c| Ok(Token::Constant(Constant::Fixnum(c as isize))))
|
.map(|c| Token::Constant(Constant::Fixnum(c as isize)))
|
||||||
.or_else(|_| {
|
.or_else(|_| {
|
||||||
self.return_char(c);
|
self.return_char(c);
|
||||||
|
|
||||||
|
|||||||
@@ -484,7 +484,7 @@ impl<'a, R: Read> Parser<'a, R> {
|
|||||||
if self.atomize_term(&self.terms[idx - 1]).is_some() {
|
if self.atomize_term(&self.terms[idx - 1]).is_some() {
|
||||||
self.stack.truncate(stack_len + 1);
|
self.stack.truncate(stack_len + 1);
|
||||||
|
|
||||||
let mut subterms: Vec<_> = self.terms.drain(idx..).map(|t| Box::new(t)).collect();
|
let mut subterms: Vec<_> = self.terms.drain(idx..).map(Box::new).collect();
|
||||||
|
|
||||||
if let Some(name) = self.terms.pop().and_then(|t| self.atomize_term(&t)) {
|
if let Some(name) = self.terms.pop().and_then(|t| self.atomize_term(&t)) {
|
||||||
// reduce the '.' functor to a cons cell if it applies.
|
// reduce the '.' functor to a cons cell if it applies.
|
||||||
@@ -722,8 +722,8 @@ impl<'a, R: Read> Parser<'a, R> {
|
|||||||
|
|
||||||
let idx = self.stack.len() - 2;
|
let idx = self.stack.len() - 2;
|
||||||
|
|
||||||
match self.stack.remove(idx) {
|
let td = self.stack.remove(idx);
|
||||||
td => match td.tt {
|
match td.tt {
|
||||||
TokenType::Open | TokenType::OpenCT => {
|
TokenType::Open | TokenType::OpenCT => {
|
||||||
if self.stack[idx].tt == TokenType::Comma {
|
if self.stack[idx].tt == TokenType::Comma {
|
||||||
return false;
|
return false;
|
||||||
@@ -740,7 +740,6 @@ impl<'a, R: Read> Parser<'a, R> {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
_ => false,
|
_ => false,
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -756,7 +755,7 @@ impl<'a, R: Read> Parser<'a, R> {
|
|||||||
match self.tokens.last().ok_or(ParserError::UnexpectedEOF)? {
|
match self.tokens.last().ok_or(ParserError::UnexpectedEOF)? {
|
||||||
// do this when layout hasn't been inserted,
|
// do this when layout hasn't been inserted,
|
||||||
// ie. why we don't match on Token::Open.
|
// ie. why we don't match on Token::Open.
|
||||||
&Token::OpenCT => {
|
Token::OpenCT => {
|
||||||
// can't be prefix, so either inf == 0
|
// can't be prefix, so either inf == 0
|
||||||
// or post == 0.
|
// or post == 0.
|
||||||
self.reduce_op(inf + post);
|
self.reduce_op(inf + post);
|
||||||
@@ -831,16 +830,16 @@ impl<'a, R: Read> Parser<'a, R> {
|
|||||||
|
|
||||||
fn atomize_term(&self, term: &Term) -> Option<ClauseName> {
|
fn atomize_term(&self, term: &Term) -> Option<ClauseName> {
|
||||||
match term {
|
match term {
|
||||||
&Term::Constant(_, ref c) => self.atomize_constant(c),
|
Term::Constant(_, ref c) => self.atomize_constant(c),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn atomize_constant(&self, c: &Constant) -> Option<ClauseName> {
|
fn atomize_constant(&self, c: &Constant) -> Option<ClauseName> {
|
||||||
match c {
|
match c {
|
||||||
&Constant::Atom(ref name, _) => Some(name.clone()),
|
Constant::Atom(ref name, _) => Some(name.clone()),
|
||||||
&Constant::Char(c) => Some(clause_name!(c.to_string(), self.lexer.atom_tbl)),
|
Constant::Char(c) => Some(clause_name!(c.to_string(), self.lexer.atom_tbl)),
|
||||||
&Constant::EmptyList => Some(clause_name!(c.to_string(), self.lexer.atom_tbl)),
|
Constant::EmptyList => Some(clause_name!(c.to_string(), self.lexer.atom_tbl)),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -892,7 +891,7 @@ impl<'a, R: Read> Parser<'a, R> {
|
|||||||
self.negate_number(n, negate_rc, Constant::Rational)
|
self.negate_number(n, negate_rc, Constant::Rational)
|
||||||
}
|
}
|
||||||
Token::Constant(Constant::Float(n)) => {
|
Token::Constant(Constant::Float(n)) => {
|
||||||
self.negate_number(n, |n| OrderedFloat(-n.into_inner()), |n| Constant::Float(n))
|
self.negate_number(n, |n| OrderedFloat(-n.into_inner()), Constant::Float)
|
||||||
}
|
}
|
||||||
Token::Constant(c) => {
|
Token::Constant(c) => {
|
||||||
if let Some(name) = self.atomize_constant(&c) {
|
if let Some(name) = self.atomize_constant(&c) {
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ impl<T: Hash + Eq> Hash for TabledRc<T> {
|
|||||||
impl<T: Hash + Eq + ToString> TabledRc<T> {
|
impl<T: Hash + Eq + ToString> TabledRc<T> {
|
||||||
pub fn new(atom: T, table: TabledData<T>) -> Self {
|
pub fn new(atom: T, table: TabledData<T>) -> Self {
|
||||||
let atom = match table.borrow_mut().take(&atom) {
|
let atom = match table.borrow_mut().take(&atom) {
|
||||||
Some(atom) => atom.clone(),
|
Some(atom) => atom,
|
||||||
None => Rc::new(atom),
|
None => Rc::new(atom),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user