parseComp method

Component parseComp(
  1. Lexer lexer
)

Implementation

Component parseComp(Lexer lexer) {
  if (lexer.type == TokenType.number) {
    final Factor fact = Factor(lexer.getTokenAsInt());
    lexer.consume();
    return fact;
  } else if (lexer.type == TokenType.symbol) {
    return parseSymbol(lexer);
  } else if (lexer.type == TokenType.none) {
    throw UcumException(
        'Unexpected end of expression looking for a symbol or a number');
  } else if (lexer.type == TokenType.open) {
    lexer.consume();
    final Term res = parseTerm(lexer, true);
    if (lexer.type == TokenType.close) {
      lexer.consume();
    } else {
      throw UcumException(
          "Unexpected Token Type '${lexer.type}' looking for a close bracket");
    }
    return res;
  } else {
    throw UcumException('Unexpected token looking for a symbol or a number');
  }
}