Exemplo n.º 1
0
/**
 * The string stream contains the value '0b' or '0B'.
 * @returns BINARY_NUMERAL |
 *          BINARY_NUMERAL_WITH_INT_TYPE_SUFFIX |
 *          ERROR.
 */
LiteralToken LiteralSupport::getBinaryNumeral(u32string &ss) {
  // Lookahead and confirm that we have valid binary digit.
  char32_t c = src->getChar();
  if (!isBinaryDigit(c)) {
    src->ungetChar(3);
    return LiteralToken::ERROR;
  }

  // Append bin digit we've just consumed
  ss += c;

  // Consume remaining digits
  consumeDigitsPOrUnderscores(ss, isBinaryDigit);

  // Check int type suffix
  char peek = src->peekChar();
  if (isIntegerTypeSuffix(peek)) {
    ss += src->getChar(); // append and consume suffix
    return LiteralToken::BINARY_NUMERAL_WITH_INT_TYPE_SUFFIX;
  }

  return LiteralToken::BINARY_NUMERAL;
}
Exemplo n.º 2
0
Token Scanner::readNumber()
{
    if (!m_src.isEnd()) {
        QChar ch = m_src.peek();
        if (ch.toLower() == 'b') {
            m_src.move();
            while (isBinaryDigit(m_src.peek()))
                m_src.move();
        } else if (ch.toLower() == 'o') {
            m_src.move();
            while (isOctalDigit(m_src.peek()))
                m_src.move();
        } else if (ch.toLower() == 'x') {
            m_src.move();
            while (isHexDigit(m_src.peek()))
                m_src.move();
        } else { // either integer or float number
            return readFloatNumber();
        }
        if (isValidIntegerSuffix(m_src.peek()))
            m_src.move();
    }
    return Token(Token::Number, m_src.anchor(), m_src.length());
}