Example #1
0
    QualifiedName TypeParser::parseQualifiedName(bool adjustForIdentifier) {
        QualifiedName name;

        for (;;) {
            // have to start with an identifier
            if (_helper->peek().type() != Token::Type::Identifier) {
                assert(0 && "Message: Invalid multi-part identifier");
            }

            name.appendComponent(_helper->nextStr());

            // need two successive colons to continue
            if (_helper->peek().type() != Token::Type::PunctuationColon) {
                break;
            }

            if (_helper->peek(2).type() != Token::Type::PunctuationColon) {
                break;
            }

            // check for and handle the case of empty specifiers
            if (_helper->peek(3).type() != Token::Type::Identifier) {
                break;
            }

            _helper->next();
            _helper->next();
        }

        if (adjustForIdentifier) {
            // do an adjustment to seperate the name from the namspace parts
            name.shiftLastComponentToName();
        }

        return name;
    }
Example #2
0
    bool TypeParser::peekQualifiedName(uint32_t* peekDepth, QualifiedName& peekedName) {
        assert(peekDepth);

        for (;;) {
            // We have to lead with an identifier
            if (_helper->peek(*peekDepth).type() != Token::Type::Identifier) {
                return false;
            }

            peekedName.appendComponent(_helper->peek(*peekDepth).str());
            *peekDepth += 1;

            // check for "::"
            if (_helper->peek(*peekDepth).type() != Token::Type::PunctuationColon) {
                break;
            }

            if (_helper->peek(*peekDepth + 1).type() != Token::Type::PunctuationColon) {
                break;
            }

            // Check for the empty specifier case of "Int::4"
            if (_helper->peek(*peekDepth + 2).type() != Token::Type::Identifier) {
                break;
            }

            // move past the "::", and check for the next identifier part
            *peekDepth += 2;
        }

        // We've treated every identifier as a namespace, because its convenient. But,
        // the last component is really the identifier itself (ie the name).
        peekedName.shiftLastComponentToName();

        return true;
    }