Exemplo n.º 1
0
void Parser::allocTable(std::string actionSym, std::string gotoSym, int rows)
{
	if (mActionTable)
	{
		delete mActionTable;
		mActionTable = NULL;
	}
	if (mGotoTable)
	{
		delete mGotoTable;
		mGotoTable = NULL;
	}
	if (!rows)
		return;
	//=========================================================
	// build ACTION and GOTO field string
	std::string actionRow = trim(repeat("_ ", countText(actionSym, " ") + 1));
	std::string gotoRow = trim(repeat("_ ", countText(gotoSym, " ") + 1));
	//=========================================================
	mActionTable = new ParserTable(actionSym);
	mGotoTable = new ParserTable(gotoSym);
	for (int i = 0; i < rows; i++)
	{
		mActionTable->addRow(
			new ParserRow(&mActionTable->getSymTableR(), actionRow)
			);
		mGotoTable->addRow(
			new ParserRow(&mGotoTable->getSymTableR(), gotoRow)
			);
	}
}
Exemplo n.º 2
0
void OsmAnd::TextRasterizer_P::measureHaloGlyphs(
    const Style& style,
    const QVector<LinePaint>& paints,
    QVector<SkScalar>& outGlyphWidths) const
{
    for (const auto& linePaint : constOf(paints))
    {
        for (const auto& textPaint : constOf(linePaint.textPaints))
        {
            const auto haloPaint = getHaloPaint(textPaint.paint, style);

            const auto glyphsCount = haloPaint.countText(
                                         textPaint.text.constData(),
                                         textPaint.text.length()*sizeof(QChar));
            const auto previousSize = outGlyphWidths.size();
            outGlyphWidths.resize(previousSize + glyphsCount);
            const auto pWidth = outGlyphWidths.data() + previousSize;
            haloPaint.getTextWidths(
                textPaint.text.constData(),
                textPaint.text.length()*sizeof(QChar),
                pWidth);

            *pWidth += -textPaint.bounds.left();
        }
    }
}
Exemplo n.º 3
0
std::string Parser::getAction(
	std::stack<std::string> &frameStack,
	std::stack<std::string> &pStack, std::list<int> &output,
	std::string expr, int &s, std::string &a, int &ip, int &ip2,
	std::map<std::string, bool> &visMap
	)
{
	std::string result;
	s = val(pStack.top()); // let "s" be stack top
	a = scanText(expr, ip2 = ip, " "); // let "a" be next token
	if ((result = (*mActionTable)[s][a]) == "_") // if error
		if (!frameStack.empty()) // if more alternatives to try
		{
			//=========================================================
			// pop branch info
			std::string name = popStack(frameStack); // get branch NAME
			int branchCnt = val(popStack(frameStack)); // get branch COUNT
			int branch = val(popStack(frameStack)); // get branch INDEX
			//=========================================================
			this->applyState(
				frameStack, pStack, output, s, a, ip, ip2, result
				); // apply branch STATE
			//=========================================================
			// push branch info
			frameStack.push(cstr(branch)); // push branch INDEX
			frameStack.push(cstr(branchCnt)); // push branch COUNT
			frameStack.push(name); // push branch NAME
			//=========================================================
		}
	//=========================================================
	std::string name =
		cstr(s) + "_" + a + "_" + cstr(ip); // build branch NAME
	std::string state = name + "_" +
		right(readSeq(output), LOOP_SAMPLE_LEN); // build parser STATE
	//=========================================================
	if (result.find(" ") != -1) // if multiple actions possible
	{
		int branchCnt = 1; // init branch COUNT
		int branch = 0; // init branch INDEX
		if (
			!frameStack.empty() && name == frameStack.top()
			) // if revisiting branch
		{
			//=========================================================
			// pop branch info
			frameStack.pop(); // pop branch NAME
			branchCnt = val(popStack(frameStack)); // get branch COUNT
			branch = val(popStack(frameStack)); // get branch INDEX
			//=========================================================
		}
		//=========================================================
		state += "_" + cstr(branch); // build parser STATE
		//=========================================================
		if (branch < branchCnt) // if branch legal
		{
			if (!branch) // if first encounter with branch
			{
				this->pushState(
					frameStack, pStack, output, s, a, ip, ip2, result
					); // push branch STATE
				branchCnt = countText(result, " ") + 1; // calc branch COUNT
			}
			//=========================================================
			result = getEntry(result, " ", branch); // choose this branch INDEX
			//=========================================================
			if (branch == branchCnt - 1) // if last encounter with branch
				this->popState(frameStack); // pop branch STATE
			else
			{
				//=========================================================
				// push branch info
				frameStack.push(cstr(branch + 1)); // push next branch INDEX
				frameStack.push(cstr(branchCnt)); // push branch COUNT
				frameStack.push(name); // push branch NAME
				//=========================================================
			}
		}
		else
			throw new Exception("parsing error");
	}
	//=========================================================
	// check for infinite recursion
	if (visMap.find(state) != visMap.end())
		throw new Exception("parsing error");
	visMap[state] = true; // mark as visited
	//=========================================================
	return result;
}