use std::fmt;
use IResult;
use Parser;
pub struct Operator<O> {
pub op: O,
pub associativity: Associativity,
pub size: OperatorSize,
pub precedence: usize,
pub parser: Parser,
}
impl<O> Operator<O> {
pub fn new(op: O,
assoc: Associativity,
size: OperatorSize,
prec: usize,
parser: Parser) -> Self {
Operator {
op: op,
associativity: assoc,
size: size,
precedence: prec,
parser: parser,
}
}
}
impl<O: fmt::Debug> fmt::Debug for Operator<O> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f,
"Operator<{:?}>: \n\tAssociativity: {:?}\n\tPrecedence: {}",
self.op,
self.associativity,
self.precedence)
}
}
impl<O: PartialEq> PartialEq for Operator<O> {
fn eq(&self, other: &Operator<O>) -> bool {
self.op == other.op &&
self.associativity == other.associativity &&
self.precedence == other.precedence
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum OperatorSize {
Unary,
Binary,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Associativity {
Left,
Right,
}