number method

void number(
  1. String c
)

Implementation

void number(String c) {
  bool isHex = false;
  if (c == '0' && peek() == 'x') {
    isHex = true;
    advance();
  }
  while (isDigit(peek(), isHex)) {
    advance();
  }
  bool isDouble = false;
  if (peek() == '.' && isDigit(peekNext(), false)) {
    isDouble = true;
    advance();
    while (isDigit(peek(), false)) {
      advance();
    }
  }

  String numberStr = source.substring(start, current);
  if (isDouble) {
    addToken1(TokenType.NUMBER, double.parse(numberStr));
  } else {
    addToken1(TokenType.NUMBER, int.parse(numberStr));
  }
}