///|
/// Arithmetic, comparison or short-circuit logical operator in a parsed expression.
/// Example: `@plural.parse_expr("n%10")`.
#derive(Eq, @debug.Debug)
pub enum BinaryOp {
  LogicalOr
  LogicalAnd
  Eq
  NotEq
  Lt
  LtEq
  Gt
  GtEq
  Add
  Sub
  Mul
  Div
  Mod
}

///|
/// Write the diagnostic representation of BinaryOp to a logger.
/// Example: `value.to_string()`.
pub impl Show for BinaryOp with fn output(self, logger) {
  logger.write_string(@debug.to_string(self))
}

///|
#derive(Eq)
priv enum Token {
  End
  Variable
  Number(UInt64)
  Operator(BinaryOp)
  Not
  LeftParen
  RightParen
  Question
  Colon
}

///|
/// Syntax, count, resource-limit or arithmetic error from parsing or evaluating plural rules.
/// Example: `rule.eval_index(2) catch { _ => 0 }`.
#derive(Eq, @debug.Debug)
pub suberror PluralError {
  MalformedPluralHeader(raw~ : String, reason~ : String)
  InvalidNplurals(value~ : String)
  UnexpectedToken(expected~ : String, found~ : String, pos~ : Int32)
  TrailingTokens(found~ : String, pos~ : Int32)
  MaxDepthExceeded(limit~ : Int32)
  DivisionByZero
  EvalLimitExceeded(limit~ : Int32)
  InvalidPluralIndex(index~ : UInt64, nplurals~ : Int32)
  UnexpectedChar(ch~ : Char, pos~ : Int32)
  IntegerOverflow(lexeme~ : String, pos~ : Int32)
}

///|
/// Write the diagnostic representation of PluralError to a logger.
/// Example: `value.to_string()`.
pub impl Show for PluralError with fn output(self, logger) {
  logger.write_string(@debug.to_string(self))
}