parseTerm method

Term parseTerm(
  1. Lexer lexer,
  2. bool first
)

Implementation

Term parseTerm(Lexer lexer, bool first) {
  final Term res = Term();
  if (first && lexer.type == TokenType.none) {
    res.comp = Factor(1);
  } else if (lexer.type == TokenType.solidus) {
    res.op = Operator.division;
    lexer.consume();
    res.term = parseTerm(lexer, false);
  } else {
    // TODO(Dokotela): this does not exactly mirror Java, but passes tests
    if (lexer.type == TokenType.annotation) {
      // Handle annotation - assuming it's skipped or processed elsewhere
      res.comp = Factor(1); // Example handling, might need to be adjusted
      lexer.consume();
    } else {
      res.comp = parseComp(lexer);
    }

    if (lexer.type != TokenType.none && lexer.type != TokenType.close) {
      if (lexer.type == TokenType.solidus) {
        res.op = Operator.division;
        lexer.consume();
      } else if (lexer.type == TokenType.period) {
        res.op = Operator.multiplication;
        lexer.consume();
      } else if (lexer.type == TokenType.annotation) {
        res.op = Operator.multiplication; // Implicit multiplication
      } else {
        throw UcumException("Expected '/' or '.'");
      }
      res.term = parseTerm(lexer, false);
    }
  }
  return res;
}