Esempio n. 1
0
ParseResults parser::LL1::parse(const std::vector<Token>& input) {
    assert(canParse());
    ParseResults result;
    std::size_t length = input.size();
    std::stack<TokenType> stack;
    stack.push(END_OF_SENTENCE);
    stack.push(getCFG()[0].getName());
    for (std::size_t i = 0; i <= length; i++) {
        const TokenType& symbol = (i < length) ? input[i].type : END_OF_SENTENCE;
        result = unwind(stack, symbol);
        if (!result.accepted) {
            return error(input, i, result.errorMessage);
        }

        if (stack.top() == symbol) {
            stack.pop();
            // ECHO("[POP] " + symbol);
        } else {
            return error(input, i, "Unexpected token '" + symbol + "', expected '" + stack.top() + "'");
        }
    }

    if (!stack.empty()) {
        return error(input, input.size(), "Unexpected end-of-sentence, expected '" + stack.top() + "'");
    }

    result.accepted = true;
    return result;
}
Esempio n. 2
0
web_color web_color::from_string(const wchar_t* str)
{
    web_color result;

    if (str)
    {
        if (canParse(str))
        {
            result = parseRGB(str);
        }
        else
        {
            if (colorMap.empty())
            {
                load_names();
            }

            auto found = colorMap.find(str);

            if (found != colorMap.end())
            {
                result = found->second;
            }
        }
    }

    return result;
}
AbstractTestParser* XUnitXMLQTestLibParserFactory::getParserInstance(ProjectExplorer::RunConfiguration *runConfiguration) const
{
    Q_ASSERT(runConfiguration != NULL);

    if (!canParse(runConfiguration))
        return NULL;
    qDebug() << "XUnitXMLQTestLibParser can parse this file";
    return new XUnitXMLQTestLibParser(runConfiguration);
}
Esempio n. 4
0
uint8 *ASTCHandler::parse(filesystem::FileData *filedata, std::vector<CompressedImageData::SubImage> &images, size_t &dataSize, CompressedImageData::Format &format, bool &sRGB)
{
	if (!canParse(filedata))
		throw love::Exception("Could not decode compressed data (not an .astc file?)");

	ASTCHeader header = *(const ASTCHeader *) filedata->getData();

	CompressedImageData::Format cformat = convertFormat(header.blockdimX, header.blockdimY, header.blockdimZ);

	if (cformat == CompressedImageData::FORMAT_UNKNOWN)
		throw love::Exception("Could not parse .astc file: unsupported ASTC format %dx%dx%d.", header.blockdimX, header.blockdimY, header.blockdimZ);

	uint32 sizeX = header.sizeX[0] + (header.sizeX[1] << 8) + (header.sizeX[2] << 16);
	uint32 sizeY = header.sizeY[0] + (header.sizeY[1] << 8) + (header.sizeY[2] << 16);
	uint32 sizeZ = header.sizeZ[0] + (header.sizeZ[1] << 8) + (header.sizeZ[2] << 16);

	uint32 blocksX = (sizeX + header.blockdimX - 1) / header.blockdimX;
	uint32 blocksY = (sizeY + header.blockdimY - 1) / header.blockdimY;
	uint32 blocksZ = (sizeZ + header.blockdimZ - 1) / header.blockdimZ;

	size_t totalsize = blocksX * blocksY * blocksZ * 16;

	if (totalsize + sizeof(header) > filedata->getSize())
		throw love::Exception("Could not parse .astc file: file is too small.");

	uint8 *data = nullptr;

	try
	{
		data = new uint8[totalsize];
	}
	catch (std::bad_alloc &)
	{
		throw love::Exception("Out of memory.");
	}

	// .astc files only store a single mipmap level.
	memcpy(data, (uint8 *) filedata->getData() + sizeof(ASTCHeader), totalsize);

	CompressedImageData::SubImage mip;

	mip.width = sizeX;
	mip.height = sizeY;

	mip.size = totalsize;
	mip.data = data;

	images.push_back(mip);

	dataSize = totalsize;
	format = cformat;
	sRGB = false;

	return data;
}
Esempio n. 5
0
uint8 *PKMHandler::parse(filesystem::FileData *filedata, std::vector<CompressedImageData::SubImage> &images, size_t &dataSize, CompressedImageData::Format &format, bool &sRGB)
{
	if (!canParse(filedata))
		throw love::Exception("Could not decode compressed data (not a PKM file?)");

	PKMHeader header = *(const PKMHeader *) filedata->getData();

	header.textureFormatBig = swap16big(header.textureFormatBig);
	header.extendedWidthBig = swap16big(header.extendedWidthBig);
	header.extendedHeightBig = swap16big(header.extendedHeightBig);
	header.widthBig = swap16big(header.widthBig);
	header.heightBig = swap16big(header.heightBig);

	CompressedImageData::Format cformat = convertFormat(header.textureFormatBig);

	if (cformat == CompressedImageData::FORMAT_UNKNOWN)
		throw love::Exception("Could not parse PKM file: unsupported texture format.");

	// The rest of the file after the header is all texture data.
	size_t totalsize = filedata->getSize() - sizeof(PKMHeader);
	uint8 *data = nullptr;

	try
	{
		data = new uint8[totalsize];
	}
	catch (std::bad_alloc &)
	{
		throw love::Exception("Out of memory.");
	}

	// PKM files only store a single mipmap level.
	memcpy(data, (uint8 *) filedata->getData() + sizeof(PKMHeader), totalsize);

	CompressedImageData::SubImage mip;

	// TODO: verify whether glCompressedTexImage works properly with the unpadded
	// width and height values (extended == padded.)
	mip.width = header.widthBig;
	mip.height = header.heightBig;

	mip.size = totalsize;
	mip.data = data;

	images.push_back(mip);

	dataSize = totalsize;
	format = cformat;
	sRGB = false;

	return data;
}
Esempio n. 6
0
bool web_color::is_color(const wchar_t* str)
{
    if (canParse(str))
    {
        return true;
    }
    
    if (colorMap.empty())
    {
        load_names();
    }

    return colorMap.find(str) != colorMap.end();
}
Esempio n. 7
0
ParseResults parser::SLR1::parse(const std::vector<Token>& tokens) {
    assert(canParse());
    ParseResults results;
    std::stack<std::size_t> stateStack;
    stateStack.push(0);
    std::size_t inputPointer = 0;
    Symbol nonTerminalBuffer;
    while (true) {
        TokenType currToken;
        if (!nonTerminalBuffer.empty()) {
            currToken = nonTerminalBuffer;
        } else if (inputPointer < tokens.size()) {
            currToken = tokens[inputPointer].type;
        } else {
            currToken = "EOS";
        }
        auto& currState = table[stateStack.top()];
        if (currState.count(currToken) == 0) {
            return error(tokens, inputPointer, "Unexpected token '" + currToken + "'");
        }

        AscendingAction& action = currState[currToken];
        switch (action.action) {
            case Action::ACCEPT:
                results.accepted = true;
                return results;
            case Action::GOTO:
                stateStack.push(action.target);
                nonTerminalBuffer.clear();
                break;
            case Action::REDUCE: {
                const Production& prod = getCFG()[action.target];
                for (std::size_t i = 0; i < prod.size(); i++) {
                    stateStack.pop();
                }
                nonTerminalBuffer = prod.getName();
                break;
            }
            case Action::SHIFT:
                stateStack.push(action.target);
                inputPointer++;
                break;
            default:
                assert(false);
        }
    }
}