package scotch.symbol;
import static lombok.AccessLevel.PRIVATE;
import static scotch.symbol.Value.Fixity.LEFT_INFIX;
import static scotch.symbol.Value.Fixity.PREFIX;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import scotch.symbol.Value.Fixity;
@AllArgsConstructor(access = PRIVATE)
@EqualsAndHashCode(callSuper = false)
@ToString
public class Operator {
public static Operator operator(Fixity fixity, int precedence) {
return new Operator(fixity, precedence);
}
private final Fixity fixity;
private final int precedence;
public boolean hasLessPrecedenceThan(Operator other) {
return precedence < other.precedence;
}
public boolean hasSamePrecedenceAs(Operator other) {
return precedence == other.precedence;
}
public boolean isLeftAssociative() {
return fixity == LEFT_INFIX;
}
public boolean isPrefix() {
return fixity == PREFIX;
}
}